Iphone 调用UITableView';要从ParserDidEndDocument更新的方法,UITableView为空?
我发现了一些关于这个话题的问题,但我的问题似乎已经解决了。我有一个iPhone应用程序,它从服务器提取XML提要,对其进行解析,然后在三个UITableView中显示数据(在解析时进行排序)。目前,我有N计时器在数据解析完成后更新UITables。我知道有更好的办法。我正在尝试使用解析器委托方法 在我的解析器中Iphone 调用UITableView';要从ParserDidEndDocument更新的方法,UITableView为空?,iphone,ios5,isnull,method-call,Iphone,Ios5,Isnull,Method Call,我发现了一些关于这个话题的问题,但我的问题似乎已经解决了。我有一个iPhone应用程序,它从服务器提取XML提要,对其进行解析,然后在三个UITableView中显示数据(在解析时进行排序)。目前,我有N计时器在数据解析完成后更新UITables。我知道有更好的办法。我正在尝试使用解析器委托方法 在我的解析器中 -(void)parserDidEndDocument:(NSXMLParser *)parser{ NSLog(@"done Parsing, now update UI
-(void)parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"done Parsing, now update UITable in otherViewController");
otherViewController *otherUpdatingtmp =[[otherViewController alloc] initWithNibName:@"otherViewController" bundle:nil];
[otherUpdatingtmp updateTable];
}
触发位于otherViewController上的updateTable
方法以重新加载表中的数据。我的NSLog告诉我我的updateTable
正在otherViewController线程中启动,但是我似乎无法让我的TableView更新,因为它返回为NULL
在我的otherViewController.m中
-(void)updateTable{
[tabeViewUI reloadData];
NSLog(@"update table fired. table view is %@.", tabeViewUI);
}
一定是我忽略了一些小事。提前谢谢
2012年7月24日编辑:
感谢@tc。让我开始使用[NSNotificationCenter]
在我的解析器中
-(void)parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"done Parsing, now update UITable's with NSNotification");
[[NSNotificationCenter defaultCenter] postNotificationName:@"parserDidEndDocument" object:self];}
然后在我的每个UITableView中添加:
- (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。你忘了把它贴在ivar上?@tc。我需要输入什么作为ivar?我在otherViewController.h中有“-(void)updateTable”。我是个新手,不确定'@interface otherViewController()-end'和'-implementation otherViewController'的区别是否与此有关?我不明白,我的NSLog与我当前的设置不兼容,但在同一块“[tabeViewUI reloadData];”不是吗?啊,忽略我最后的评论。您正在分配一个新的
otherViewController
,并更新其表,即使它从未显示。您需要更新现有的otherViewController
@tc。这听起来是正确的,因为我的NSLog经常为我的UITableView返回null。创建新的otherViewcontroller实例可以解释返回空表的原因。如何更新现有表?我一直在使用NSTimer从各自的线程更新我的表(我有3个),但是更需要通过“parserDidEndDocument”进行更新。您的otherViewController
应该是解析器的委托。