调用UITableView的方法从ParserDidEndDocument更新,UITableView null?

时间:2012-07-20 17:52:44

标签: iphone ios5 isnull method-call

我已经找到了一些关于这个主题的问题,但已知似乎解决了我的问题。我有一个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];
    }

触发位于otherViewController上的updateTable方法,以在表中重新加载数据。我的NSLog告诉我我的updateTable在另一个ViewController线程中被触发但是我似乎无法让我的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。

0 个答案:

没有答案