so I have a table view and whenever user press a row, another class开发者_如何学Go 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];
}
}
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.
- (void)waitForResponse
{
while (/*Some condition is not met*/)
{
}
}
Also you need to implement the
- (void) hudWasHidden
{
[HUD removeFromSuperview];
[HUD release];
}
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 )
- (void) 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.
[loading showWhileExecuting:@selector(doTheJob) onTarget:self withObject:nil animated:YES];
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.
精彩评论