我有一个UITableview顶部的导航栏。我有一个刷新按钮作为rightBarButtonItem。延迟隐藏导航右栏按钮项
当刷新按钮被点击时,我想隐藏刷新按钮,重新加载表格并显示一个alertview。
-(void)refreshClicked{
self.navigationItem.rightBarButtonItem=nil;
app.networkActivityIndicatorVisible = YES;
[appDelegate readJSONData];
[self.tableView reloadData];
UIAlertView *infoAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"Kampanjerna är nu uppdaterade" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[infoAlert show];
[infoAlert release];
}
我发现当我的wifi信号变弱时,刷新按钮不会立即隐藏,并且存在延迟。我担心,如果使用3G,会有进一步的延迟,用户可能会再次按下刷新按钮,并认为第一次没有按下按钮。
我的代码有问题吗?
帮助,将不胜感激
编辑-----------
-(void)refreshClicked{
self.navigationItem.rightBarButtonItem=nil;
app.networkActivityIndicatorVisible = YES;
// do data processing in the background
[self performSelectorInBackground:@selector(doBackgroundProcessing) withObject:self];
UIAlertView *infoAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"Kampanjerna är nu uppdaterade" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[infoAlert show];
[infoAlert release];
}
- (void)doBackgroundProcessing {
NSAutoreleasePool*pool=[[NSAutoreleasePool alloc] init];
[appDelegate readJSONData];
// must update the UI from the main thread only; equivalent to [self.tableView reloadData];
[self performSelectorOnMainThread:@selector(reloadData) withObject:self.tableView waitUntilDone:NO];
[pool release];
}
错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[campaignTableViewController reloadData]: unrecognized selector sent to instance 0x703eba0'
感谢您的回复时完成。我是iphone开发新手。你能告诉我一个例子吗? – Neelesh 2011-05-26 20:44:51
除非你打算换掉另一个按钮,否则你可能应该采纳@PenOne的建议。 – bosmacs 2011-05-26 21:42:47
这是我得到的错误。 *** __NSAutoreleaseNoPool():类NSURL的对象0x9c06910自动释放,没有池到位 - 只是漏水 – Neelesh 2011-05-26 23:10:53