質問

When I click on table cell, there's a short delay of 1-2 second before it loads the next view. I've seen some apps that show an activity indicator during that time and that's what I'd like to do. I've added one like this

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

  UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  spinner.frame = CGRectMake(200,200,200,200);
  UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  cell.accessoryView = spinner;
  [spinner startAnimating];
  [spinner release];

  VenueViewController *vviewcontroller = [[VenueViewController alloc] initWithNibName:@"VenueViewController" bundle:[NSBundle mainBundle]];

  [self.navigationController pushViewController:vviewcontroller animated:YES];
  [vviewcontroller release];
  vviewcontroller = nil;}

however this also appears with a delay, and just before the next view is showing. It seems the app freezes for 1-2 seconds after clicking on the table cell so it doesn't even show the activity indicator.

役に立ちましたか?

解決

I think the secret is that you should call load method using a performSelector method. Another tip is hiding or showing the activity so it won't consume time this operation.

So this could be a pseudocode of that

Inside your ViewController class definition:

IBOutlet UIActivityIndicatorView *spin;  // created in view and hidden

In your implementation...

-(void) load{ // your code
  VenueViewController *vviewcontroller = [[VenueViewController alloc] initWithNibName:@"VenueViewController" bundle:[NSBundle mainBundle]];

  [self.navigationController pushViewController:vviewcontroller animated:YES];
  [vviewcontroller release];
  vviewcontroller = nil;

  spin.hidden=YES;
}

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

  spinner.hidden=NO;

  [self performSelector:@selector(load) withObject:nil afterDelay:0];

}

Hope it helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top