当我点击表格单元格时,在加载下一个视图之前会有1-2秒的短暂延迟。我看到一些应用程序在这段时间内会显示一个活动指示器,这就是我想要做的。我添加了一个类似这样的
- (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;}然而,这也会延迟出现,就在下一个视图显示之前。在表格单元格上点击后,应用程序似乎会冻结1-2秒,所以它甚至不会显示活动指示器。
发布于 2012-04-21 22:09:15
我认为秘诀在于您应该使用performSelector方法调用load方法。另一个技巧是隐藏或显示活动,这样它就不会消耗此操作的时间。
所以这可能是它的伪代码
在您的ViewController类定义中:
IBOutlet UIActivityIndicatorView *spin; // created in view and hidden在你的实现中...
-(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];
}希望能有所帮助。
https://stackoverflow.com/questions/10245248
复制相似问题