选择一个后,在UITableView中切换单元格并调用performSegueWithIdentifier:sender:

时间:2012-08-02 21:06:45

标签: objective-c ios uitableview

我遇到了UITableView的麻烦并且从中脱颖而出。表格视图包含一个地点列表,当单击一个单元格时,它会从该位置切换到一系列照片。加载这些照片的信息需要花费一些时间,因此它会在一些地方列出。我的问题是,我不想在用户加载时冻结用户,如果用户决定切换他们想要的地方,我希望他们能够。有没有一个简单的解决方案,还是需要重新设计?这是单击单元格时调用的内容:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [self.activityIndicator startAnimating];
    [[tableView cellForRowAtIndexPath:indexPath] setAccessoryView:self.activityIndicator];
    self.query = ^{return [FlickrFetcher photosInPlace:self.locationDataArray[indexPath.row] maxResults:50];};
    self.locationSelected = [[self.locationDataArray[indexPath.row] valueForKeyPath:@"_content"] componentsSeparatedByString:@","][0];
    [self performSelector:@selector(pushView:) withObject:tableView afterDelay:0.0]; // Allows spinner to start spinning before the segue is actually performed. 
}

- (void)pushView:(UITableView *)tableView {
    [self performSegueWithIdentifier:@"Display Image List" sender:self];
}

我已经尝试将performSegueWithIdentifire:sender:发送到主队列,但没有运气(无论如何我认为它不会起作用)。查询是目标视图控制器执行的操作。关于如何让它发挥作用的任何想法?

2 个答案:

答案 0 :(得分:0)

我认为,您应该在主线程上执行segue(无调度),并在其单元格中启动带有activityIndi​​cator的新(空)tableview。将在viewDidLoad方法中调度提取图像,并在加载完成后“通知”视图,然后重新加载tableView。

与本教程中一样(使用简单的NSInvocationOperation来运行后台下载): http://www.icodeblog.com/2010/03/04/iphone-coding-turbo-charging-your-apps-with-nsoperation/

祝你好运!

答案 1 :(得分:0)

我认为你可以拥有一个控制器用于你的照片列表视图,并且在该控制器的viewDidLoad中,你可以使用Grand Central Dispatch异步加载你的照片并重新加载该表的数据。