總之,是這樣的:
// Schedule a timer repeating every 2 seconds
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self.tableView
selector:@selector(reloadData)
userInfo:nil
repeats:YES];
加長版:
你需要從一個計時器調用-doParse,獲取數據,做分析,並重新加載數據。
爲了不阻塞主線程,您必須不是從主線程調用[[NSXMLParser alloc] initWithContentsOfURL:theURL]
。
相反:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:theURL];
...
// finish parsing
dispatch_async(dispatch_get_main_queue(), ^{
[tableView reloadData];
});
});
並調用-doParse
從-viewDidLoad一個的NSTimer:
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(doParse)
userInfo:nil
repeats:YES];
延伸閱讀: WWDC 2012屆211 - iOS上構建併發用戶界面。
幫助我pleseeeeee – Vasuta 2012-08-20 09:36:31