Reputation: 3125
I've got a small problem that seems to haunt me. My UITableViewController Subclass loads Data in an asynchronous matter on Selection of a TableViewCell. like this...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"clickROW");
itemData *selectedItemData;;
selectedItemData = [[[DataManager sharedDataManger]getAllDataItems] objectAtIndex:indexPath.row];
[[DataManager sharedMischaManager] loadDataItemDetailsAsync:selectedItemData.Now];
Ok, so far so good, loadDataItemDetailsAsync
posts a Notification after it has finished loading. Then my UITableViewController subclass gets properly notified, creates a new View and pushes it onto its NavigationController..
everything works fine so far...
but, because the asynchronous loading can take a while (depending on current bandwith), I want a UIActivityIndicatior being displayed / animated while the loading takes place.
So what i did was the following (in my UITableViewCell Subclass)
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
if(selected)
{
[self.contentView bringSubviewToFront:loader];
[tvImageView setHidden:YES];
[loader setHidden:NO];
[loader startAnimating];
//[loader performSelectorInBackground: @selector(startAnimating) withObject: nil];
}
else {
//[loader performSelectorInBackground: @selector(stopAnimating) withObject: nil];
[loader stopAnimating];
[loader setHidden:YES];
[tvImageView setHidden:NO];
}
}
i tried both ways to "start the loader", the performSelectorInBackGround
-way and the simple [loader startAnimating]
-way. neither of them really work.
interestingly, the tvImageView doesn't get hidden either.
I guess I'm missing out on a basic step (something like redrawing / redisplaying , i don't know) I just seem to be unable to figure it out by myself :(
any help, tipps, hints veeeery appreciated
cheers
sam
Upvotes: 0
Views: 723
Reputation: 34935
If you use Core Data (even with a simple in-memory database if you don't need to persist to disk) combined with a NSFetchedResultsController
then you don't have to deal with all the state management.
You would simply make changes to the objects and the NSFetchedResultsController
will then notify a delegate (which your UITabelViewController should implement) of any changed objects. In that delegate you would simply make changes to the UITableViewCell, like showing/hiding a activity indicator or status text.
All this with a simple and formal protocol.
Check NSFetchedResultsControllerDelegate Protocol Reference for a good overview.
Upvotes: 1