I have found a few questions regarding this topic but known seem to get my problem solved. I have an iPhone app that pulls and XML feed from a server, parses it, then displays the data in three UITableViews (sorting occurs at parsing). I currently have NSTimers to update the UITables once the data is done being parsed. I know there is a better way. I am trying to use the parser delegate method
In my Parser.m
-(void)parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"done Parsing, now update UITable in otherViewController");
otherViewController *otherUpdatingtmp =[[otherViewController alloc] initWithNibName:@"otherViewController" bundle:nil];
[otherUpdatingtmp updateTable];
}
to trigger the updateTable
method that is located on the otherViewController to reloadData in the table. My NSLog tells me my updateTable
is firing in the otherViewController thread however I can not seem to get my TableView to update because its returned as NULL
.
In my otherViewController.m
-(void)updateTable{
[tabeViewUI reloadData];
NSLog(@"update table fired. table view is %@.", tabeViewUI);
}
It's gotta be something small i've overlooked. Thanks in advance!
EDIT 7/24/12:
Thanks to @tc. for turning me onto using [NSNotificationCenter]
in my parser.m
-(void)parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"done Parsing, now update UITable's with NSNotification");
[[NSNotificationCenter defaultCenter] postNotificationName:@"parserDidEndDocument" object:self];}
then in each of my UITableViews I added:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTable) name:@"parserDidEndDocument" object:nil];
}
return self;
}
lastly:
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
I hope this helps someone else. It certainly helped me! Thanks @tc.