Ios 如何解决此委托错误?

Ios 如何解决此委托错误?,ios,xcode,delegates,Ios,Xcode,Delegates,我有一个委托,但如果没有另一个委托行,它就无法工作: - (id)initWithData:(NSData *)data delegate:(id <ParseOperationDelegate>)theDelegate { self = [super init]; if (self != nil) { self.dataToParse = data; self.delegate = theDelegate; }

我有一个委托,但如果没有另一个委托行,它就无法工作:

- (id)initWithData:(NSData *)data delegate:(id <ParseOperationDelegate>)theDelegate {

    self = [super init];

    if (self != nil) {
        self.dataToParse = data;
        self.delegate = theDelegate;
    }

    appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];

    return self;
}

您的代码似乎在等待某个事件,或某些文件被获取或下载,因此您需要调用
[tableview reloadData]下载此数据时

我无法从代码中找到答案,但我的直觉告诉我这一点

第一: 您正在等待来自int
nodeCount=[appDelegate.products count]的数据准备就绪,因此您需要有某种类型的委托,该委托在数据准备就绪时被调用

第二: 您正在等待在此处下载映像
[self startImageDownload:listedProduct forIndexPath:indexPath]
,因此,当实际下载映像时,您需要将映像设置为该单元格或在表上重新加载数据


这就是我从代码中可以理解的。

请更具体地说,另一个委托行是什么?当你说“它应该在单元格中加载数据”时,我看不到这方面的代码。我们是否也需要查看“
cellforrowatinexpath:
”方法的代码?@OmarAbdelhafith my PaseOperationDelegate是一个私有id委托。当我删除appDelegate=(XMLAppDelegate*)时。。。牢房里甚至没有人。这是我的问题。@MichaelDautermann请看一看。既然您的
cellforrowatinexpath:
方法引用了
appDelegate
,为什么您会惊讶于它在未设置的情况下不起作用?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"productCell";
    static NSString *PlaceholderCellIdentifier = @"placeholderCell";

    int nodeCount = [appDelegate.products count];

    if (nodeCount == 0 && indexPath.row == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PlaceholderCellIdentifier];
            cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }

        cell.detailTextLabel.text = @"Loading...";

        return cell;
    }

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    if (nodeCount > 0) {
        XMLProductView *listedProduct = [appDelegate.products objectAtIndex:indexPath.row];

        cell.textLabel.text = listedProduct.name;
        // cell.detailTextLabel.text = appRecord.artist;

        if (!listedProduct.productImage) {
            if (self.tableView.dragging == NO && self.tableView.decelerating == NO) {
                [self startImageDownload:listedProduct forIndexPath:indexPath];
            }
            UIImageView *listedImage = (UIImageView *)[cell viewWithTag:1];
            listedImage.image = [UIImage imageNamed:@"Placeholder.png"];
        }
        else {
            UIImageView *listedImage = (UIImageView *)[cell viewWithTag:1];
            listedImage.image = listedProduct.productImage;
        }

    }

    return cell;
}