我发现了一些关于这个主题的问题,但已知似乎解决了我的问题。我有一个 iPhone 应用程序,它从服务器提取和 XML 提要,对其进行解析,然后在三个 UITableViews 中显示数据(在解析时进行排序)。一旦数据完成解析,我目前有 NSTimers 来更新 UITables。我知道有更好的方法。我正在尝试使用解析器委托方法
在我的 Parser.m
-(void)parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"done Parsing, now update UITable in otherViewController");
otherViewController *otherUpdatingtmp =[[otherViewController alloc] initWithNibName:@"otherViewController" bundle:nil];
[otherUpdatingtmp updateTable];
}
触发updateTable
位于 otherViewController 上的方法以重新加载表中的数据。我的 NSLog 告诉我我updateTable
正在 otherViewController 线程中触发,但是我似乎无法让我的 TableView 更新,因为它返回为NULL
.
在我的 otherViewController.m
-(void)updateTable{
[tabeViewUI reloadData];
NSLog(@"update table fired. table view is %@.", tabeViewUI);
}
这一定是我忽略的小事。提前致谢!
编辑 7/24/12:感谢@tc。让我开始使用[NSNotificationCenter]
在我的 parser.m
-(void)parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"done Parsing, now update UITable's with NSNotification");
[[NSNotificationCenter defaultCenter] postNotificationName:@"parserDidEndDocument" object:self];}
然后在我添加的每个 UITableViews 中:
- (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;
}
最后:
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
我希望这对其他人有帮助。它当然帮助了我!谢谢@tc。