UITableViewController executes delate functions before network request finishes
Posted
by
user1543132
on Stack Overflow
See other posts from Stack Overflow
or by user1543132
Published on 2012-10-23T04:42:33Z
Indexed on
2012/10/23
5:03 UTC
Read the original article
Hit count: 160
I'm having trouble trying to populate a UITableView
with the results of a network request. It seems that my code is alright as it works perfectly when my network is speedy, however, when it's not, the function
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath-
still executes, which results in a bad access error. I presume that this is because the array that the aforesaid function attempts to utilize has not been populated. This brings me to my question: Is there anyway that I can have the UITableView
delegate methods delayed to avoid this?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"AlbumsCell";
//UITableViewCell *basicCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
AlbumsCell *cell = (AlbumsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
**// Here is where the Thread 1: EXC_BAD_ACCESS (code=2 address=0x8)**
cell = [[[AlbumsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
Album *album = [_albums objectAtIndex:[indexPath row]];
[cell setAlbum:album];
return cell;
}
© Stack Overflow or respective owner