0

我有一个代表,但如果没有其他代表行,它就无法工作:

- (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;
}

它应该在单元格中加载数据,但在第一次滚动之前不显示数据。我能做些什么?

编辑:

- (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;
}
4

1 回答 1

2

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

我无法从代码中弄清楚,但我的直觉告诉我

第一个:您正在等待来自 int 的数据nodeCount = [appDelegate.products count];准备好,因此您需要有某种委托,当该数据准备好时会调用该委托

第二:您正在等待在这里下载图像[self startImageDownload:listedProduct forIndexPath:indexPath],因此当实际下载此图像时,您需要将图像设置到该单元格或reloadData桌子上

这就是我可以从代码中得出的结论。

于 2012-06-09T09:37:06.783 回答