Iphone 隐藏导航右栏按钮项时出现延迟

Iphone 隐藏导航右栏按钮项时出现延迟,iphone,objective-c,xcode,uitableview,Iphone,Objective C,Xcode,Uitableview,我有一个顶部有导航栏的UITableview。我有一个刷新按钮作为右按钮 单击刷新按钮时,我想隐藏刷新按钮,重新加载表并显示alertview -(void)refreshClicked{ self.navigationItem.rightBarButtonItem=nil; app.networkActivityIndicatorVisible = YES; [appDelegate readJSONData]; [self.tableView reloadDa

我有一个顶部有导航栏的UITableview。我有一个刷新按钮作为右按钮

单击刷新按钮时,我想隐藏刷新按钮,重新加载表并显示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'

基本上,尽管您为nil
RightBarButtonim
,但在控件返回到应用程序的主运行循环之前,该更改不会反映在UI中。因此,如果您的方法的其余部分需要一些明显的时间(就像处理网络请求一样),那么在完成该工作之前,您不会看到按钮消失

更直接地说:您正在阻塞主线程;要修复它,您需要在后台线程上执行耗时的工作

类似的东西应该可以工作(既不编译也不测试):


为什么不禁用“刷新”按钮呢?它要简单得多,我个人认为这是用户所期望的。它是一种用于众多软件应用程序的范例。如果我按了一个按钮,我真的想让它消失吗?为什么它消失了,它坏了吗??如果它被禁用,并且用户可以看到正在发生的事情(活动指示器、警报框-可能是过度杀戮?),那么他们将更有信心您的应用程序以可预测和可靠的方式运行

myButton.isEnabled = NO;
//在你做事时设置活动指示器

//稍后完成时

myButton.isEnabled = YES;

谢谢你的回复。我是iphone开发新手。你能给我举个例子吗?你可能也应该采纳@PengOne的建议,除非你打算把按钮换成另一个。这是我得到的错误。***__NSAutoreleaseNoPool():NSURL类的对象0x9c06910在没有池的情况下自动释放-正在泄漏-(void)doBackgroundProcessing{NSAutoreleasePool*pool=[[NSAutoreleasePool alloc]init];[appDelegate readJSONData];//必须仅从主线程更新UI;相当于[self.tableView reloadData];[self-performSelectorOnMainThread:@selector(reloadData)with-Object:self.tableView waitUntilDone:NO];[pool release];}您是否尝试过将NSAutoreleasePool放置在您调用线程的位置,如上所述?
myButton.isEnabled = YES;