0

所以我有一个表格视图,每当用户按下一行时,就会出现另一个类视图。所以我想在过渡之间有一个加载指示器。我正在使用 MBProgressHUD,但是当我按下该行时它什么也没显示。我应该在@selector() 里面放什么?

[加载 showWhileExecuting:@selector() onTarget:self withObject:[NSNumber numberWithInt:i] animated:YES];

这是我的代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

loading = [[MBProgressHUD alloc] initWithView:self.view];

[self.view addSubview:loading];

loading.delegate = self;

loading.labelText = @"Loading Events, Please Wait..";

[loading showWhileExecuting:@selector(//what should I put) onTarget:self withObject:nil animated:YES]; 

[tableView deselectRowAtIndexPath:indexPath animated:YES];


    if ([[self.citiesArray objectAtIndex:indexPath.row] isEqual:@"NEW YORK"])
     {
            self.newYorkViewController = [[NewYorkViewController alloc] initWithNibName:@"NewYorkViewController" bundle:nil];
              Twangoo_AppAppDelegate *delegate = (Twangoo_AppAppDelegate*)[[UIApplication sharedApplication] delegate];
            [delegate.citiesNavController pushViewController:self.newYorkViewController animated:YES];
      }

}
4

2 回答 2

0

您需要实现一个等待功能,以便当控件从该方法返回时,HUD 将从屏幕上隐藏/消失。所以它基本上是你在屏幕上显示HUD时所做的,它可能是一些处理或等待http请求的响应等。它也可以是一个计时器。

- (void)waitForResponse
{
    while (/*Some condition is not met*/)
    {

    }
}

您还需要实施

- (void) hudWasHidden
{
    [HUD removeFromSuperview];
    [HUD release];
}
于 2011-08-03T06:08:48.277 回答
0

你可以看看关于选择器的 Cocoa 文档章节

选择器可以简单地看作是一个函数的指针。

然后,我猜您正在尝试在特定进程运行时显示进度 hud .. 从逻辑上讲,这个特定进程应该在专用方法中隔离(我们称之为 doTheJob )。

  • 所以首先创建一个名为whatever的专用方法(这里是doTheJob)

    - (void) doTheJob;
    
  • 话虽如此,MBProgressHUD 允许您使用 showWhileExecuting 方法简单地指定应该由进度信息处理的工作方法。选择器在这里定义目标工作方法。

    [loading showWhileExecuting:@selector(doTheJob) onTarget:self withObject:nil animated:YES];
    
  • 目标将是定义选择器的对象引用。为简单起见,如果您在当前类中定义方法 doTheJob,则使用 self 作为目标。

  • 而 withObject 是您想要/需要提供给选择器方法的任何参数。请注意,如果您需要为目标方法提供参数,则需要使用尾随冒号扩展选择器定义为 @selector(doTheJob:)

希望这可以帮助。

于 2011-08-03T06:12:12.073 回答