解析器(在单独的线程上)完成后,我一直试图添加一个按钮。我知道你不能在主线程以外的任何线程上与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