解析器(在單獨的線程上)完成後,我一直試圖添加一個按鈕。我知道你不能在主線程以外的任何線程上與UI元素進行交互。解析器(在單獨的線程上)完成後添加UIButton
我不想用一個定時器,或while語句...所以我的問題是
一旦你有什麼建議我做的按鈕添加到視圖解析器做了什麼?我不希望它之前添加,因爲用戶將獲得一個空白表。我也不想在完成時重新加載表格,因爲這會給我帶來其他問題。
主線程上的performSelector對我來說似乎不起作用..?我有點迷失在這裏...
有什麼建議嗎?
這裏就是我踢給另一個線程來啓動解析器(在AppDelegate中)
// begin background downloads
[NSThread detachNewThreadSelector:@selector(parseNewData) toTarget:self withObject:nil];
我parseNewData功能(在AppDelegate中)
-(void)parseNewData {
//start network activity spinner and release controller when done
RootViewController * root = [[RootViewController alloc] init];
[root downloadIcon];
[root release];
//create pool to avoid memory leak
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// get the XML path and start parsing
NSURL *pathURL = [NSURL URLWithString:@"http://www.mysite.com/file.xml"];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:pathURL];
[parser setDelegate:self];
[parser parse];
//drain pool
[pool drain];
[pool release];
}
分析器去把(在AppDelegate中)
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
// parser is finished, we can now kill the network activity icon on root view controller
RootViewController * root = [[RootViewController alloc] init];
[root killDownloadIcon];
[root performSelectorOnMainThread:@selector(unhideShowtimesButton) withObject:nil waitUntilDone:NO];
[root release];
}
上(在RootViewController的)
-(void)unhideShowtimesButton {
showtimesButton.hidden = FALSE;
}
我做它對我unhideShowtimesButton(通過斷點證實),但它只是完全無視隱藏=假我unhideShowtimesButton。
通知如何? – ennuikiller 2010-06-30 19:07:28
我添加了一些代碼,你看到什麼錯誤?謝謝! – Louie 2010-06-30 19:36:34