使用 MBProgressHUD 活动指示器
所以我有一个表视图,每当用户按下一行时,就会显示另一个类视图。所以我想在转换之间有一个加载指示器。我正在使用 MBProgressHUD,但当我按下该行时它没有显示任何内容。我应该在 @selector() 中放入什么?
[正在加载 showWhileExecuting:@selector() onTarget:self withObject:[NSNumber numberWithInt:i] 动画: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];
}
}
so I have a table view and whenever user press a row, another class view shows up. So I wanted to have a loading indicator in between the transition. I am using MBProgressHUD, but it showed nothing when I pressed the row. And what should I put inside the @selector()?
[loading showWhileExecuting:@selector() onTarget:self withObject:[NSNumber numberWithInt:i] animated:YES];
Here is my code.
- (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];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要实现一个等待函数,以便当控件从该方法返回时,HUD 将从屏幕上隐藏/消失。所以它基本上是当 HUD 显示在屏幕上时你所做的事情,它可能是一些处理或等待 http 请求的响应等。它也可以是一个计时器。
您还需要实施
You need to implement a waiting function so that when the control returns from that method the HUD will hide/disappear from the screen. So its basically what you do when the HUD is being displayed on the screen, it may be some processing or wait for response for a http request etc. It can also be a timer.
Also you need to implement the
您可能会查看 Cocoa 文档章节关于选择器
选择器可以简单地看作是一个指向函数的指针。
然后,我猜您正在尝试在特定进程运行时显示进度平显。从逻辑上讲,该特定进程应该在专用方法中隔离(我们称之为 doTheJob )。
因此,首先创建一个名为“whatever”的专用方法(此处为 doTheJob)
也就是说,MBProgressHUD 允许您使用 showWhileExecuting 方法简单地指定应由进度信息处理的工作方法。选择器在这里定义目标工作方法。
目标是定义选择器的对象引用。为了保持简单,如果您在当前类中定义方法 doTheJob,请使用 self 作为目标。
和 withObject 是您想要/需要提供给选择器方法的任何参数。请注意,如果您需要向目标方法提供参数,则需要使用尾随冒号扩展选择器定义,如 @selector(doTheJob:)
希望这会有所帮助。
You might have a look to the Cocoa documentation chapter on selectors
Selector can be simply see as a pointer to a function.
Then, I guess you are trying to display a progress hud while a particular process is running .. this particular process logically should be isolated in a dedicated method (let's call it doTheJob ).
So start by creating a dedicated method named whatever ( here doTheJob )
That being said the MBProgressHUD allows you to simply specify the working method that should be handled by the progress information using the showWhileExecuting method. And the selector is here to defined the target worker method.
The target would be the object reference that defines the selector. To remain simple, if you define the method doTheJob in the current class use self as target.
and the withObject, is any parameter that you want / need to provide to the selector method. Beware that if you need to provide parameter to the target method, you need to extend the selector definition with an trailing colon as @selector(doTheJob:)
Hope this helps.