Iphone didSelectRowAtIndexPath未显示视图
我有一个tableView,当用户选择其中一个单元格时,我会加载一个大图像 这个加载过程大约需要10秒钟,我想显示一个带有旋转图标的小视图Iphone didSelectRowAtIndexPath未显示视图,iphone,class,uiview,Iphone,Class,Uiview,我有一个tableView,当用户选择其中一个单元格时,我会加载一个大图像 这个加载过程大约需要10秒钟,我想显示一个带有旋转图标的小视图 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { loadingView = [[LoadingHUDView alloc] initWithTitle: NSLocalizedString(@"Loading i
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
loadingView = [[LoadingHUDView alloc] initWithTitle: NSLocalizedString(@"Loading image",@"")];
[self.view addSubview:loadingView];
[loadingView startAnimating];
loadingView.center = CGPointMake(self.view.bounds.size.width/2, 150);
[imageView loadImage: path];
[loadingView removeFromSuperview];
}
问题是视图(loadingView)从未显示。似乎对loadImage的调用阻止了它的显示。我可以强制显示该视图吗?问题是图像加载会束缚线程,因此视图不会用旋转图标更新
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
loadingView = [[LoadingHUDView alloc] initWithTitle: NSLocalizedString(@"Loading image",@"")];
[self.view addSubview:loadingView];
[loadingView startAnimating];
loadingView.center = CGPointMake(self.view.bounds.size.width/2, 150);
[imageView loadImage: path];
[loadingView removeFromSuperview];
}
您需要使用不同的线程,尽管这样会变得复杂,因为您无法从后台线程轻松更新视图
因此,您实际上需要做的是开始在背景线程中加载大图像
将代码加载到另一个方法中,然后在后台线程上运行它,如下所示:
[self performSelectorInBackground:(@selector(loadBigImage)) withObject:nil];
请记住,在-loadBigImage方法中,您需要声明一个NSAutorelease池:
-(void)loadBigImage {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//Code to load big image up
[pool drain];
}
当它在后台运行时,您的动画加载图标将显示得很好
希望这能帮上忙真是妙不可言!!非常感谢。