filou
filou

Reputation: 1619

How can I solve this delegate error?

I have a delegate, but it doesn't work without the other delegate line in it:

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

It should load data in a Cell but the data isn't shown before the first scroll. What can I do?

EDIT:

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

Upvotes: 0

Views: 169

Answers (1)

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

your code seems that its waiting for some event, or some files to get fetched or downloaded, so you will need to call [tableview reloadData]; when this data is downloaded,

I cant figure it out from the code, but my guts tells me this

1st: that you are waiting for data from int nodeCount = [appDelegate.products count]; to be ready, so you will need to have some sort of delegate that gets called when this data is ready

2nd: you are waiting for an image to get downloaded here [self startImageDownload:listedProduct forIndexPath:indexPath], so when this actually get downloaded you will need to set the image to that cell or reloadData on the table

That is what i can figure out from the code.

Upvotes: 2

Related Questions