Question

I am trying to load data into the application as the cells come into view so that once they press the cell's accessory button it will have the data loaded.

My problem is that I am using AFNetworking and I am using this block code:

[Request fullRequestWithBlock:^(NSArray *detailedReqFromWeb, NSError *error) {
        if (error) {

            [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:[error localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK", nil), nil] show];
        } else {

            NSArray *objs = [NSArray arrayWithObjects: [detailedReqFromWeb objectAtIndex: 0], [detailedReqFromWeb objectAtIndex: 1], [detailedReqFromWeb objectAtIndex: 2], [detailedReqFromWeb objectAtIndex: 3], [detailedReqFromWeb objectAtIndex: 4], [detailedReqFromWeb objectAtIndex: 5], nil];
            NSArray *keys = [NSArray arrayWithObjects:@"Risk", @"Destination", @"Source", @"Customer", @"Subcategory", @"Deployment", nil];

            NSMutableDictionary *detailsforRequestDictionary = [[NSMutableDictionary alloc] initWithObjects:objs forKeys:keys];

            [request addEntriesFromDictionary: detailsforRequestDictionary];

            NSLog(@"%@ Finished Loading", [idNumbers objectAtIndex:row]);
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

        }

    } forID: [[idNumbers objectAtIndex:row] substringFromIndex:1]];

So basically, I am trying to change the accessory type from the indicator to the disclosure button once the data is loaded so then I can perform a segue to another view where the data that I loaded will be shown.

My problem is that it is changing the cell.accessoryType to the button before it has finished loading. The debug NSLog actually outputs when it actually finishes loading.

What is the best way to only enable the button when it's done loading? I am guessing the request is not being processed by the main thread. How come I be notified that the request has finished processing so I can switch accessoryTypes?

Thanks!

Was it helpful?

Solution

Unless you do not recycle cells, you should never keep a cell reference around as the data it represents will change as the user scrolls. The right way is to dispatch a block on the main queue that updates a table entry in section/row coordinates. Your code then checks to see if that cell is visible, then updates it. It would also record status in some other fashion so that when the table scrolls the proper status is applied.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top