尝试同时打开多个视图会导致崩溃

时间:2014-07-23 19:31:56

标签: ios objective-c uitableview ecslidingviewcontroller

我的应用程序在tableView:didSelectRowAtIndexPath中调用一个块,并在块中显示一个视图控制器。如果我在第一次单击正在进行时第二次单击该单元格,则会崩溃。我用

解决了这个问题
tableView.userInteractionEnabled = NO;

as answered in my previous question

它解决了表的多次点击问题,但还有另一个问题。我正在使用ECSlidingViewController。用户可以滑动页面并从侧面菜单中选择一个新页面,而tableView:didSelectRowAtIndexPath仍然尝试打开另一个页面。 我试着用

 [self.view setUserInteractionEnabled:NO];

而不是

tableView.userInteractionEnabled = NO;

但它没有用。 如何防止滑动?

编辑:

以下是完整代码:

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

[tableView deselectRowAtIndexPath:indexPath animated:YES];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

__block UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.center = cell.center;
activityIndicator.hidesWhenStopped = YES;

[self.tableView addSubview:activityIndicator];
[activityIndicator startAnimating];

tableView.userInteractionEnabled = NO;

RecentItem *item = (RecentItem *) [self.recentItems objectAtIndex:indexPath.row];


 [dataController fetchAlbumWhichIncludesThisItem:item
                         success:^(VDAlbumCategory *albumCategory) {
                    NSInteger index = [albumCategory findIndexUsingNid:item.nid];
                    photos = [[NSArray alloc] initWithArray:albumCategory.photos];

                    PhotoPagesViewController *photoPagesViewController = [[PhotoPagesViewController alloc] initWithPhotos:photos];

                    NSDictionary* upperToolBarInfo = @{@"userPicturePath": item.userPicturePath,
                                                                                     @"realName": item.userName};

                    VDPhotoPagesFactory *factory = [[VDPhotoPagesFactory alloc] initWithUpperToolBarInfo:upperToolBarInfo];

                    EBPhotoPagesController *photoPagesController = [[EBPhotoPagesController alloc] initWithDataSource:photoPagesViewController delegate:photoPagesViewController photoPagesFactory: factory photoAtIndex:index];


                    [self presentViewController:photoPagesController animated:YES completion:nil];

                                                      dispatch_async(dispatch_get_main_queue(), ^{
                      [activityIndicator removeFromSuperview];

                       tableView.userInteractionEnabled = YES;
                                                  });


                                              }

}

0 个答案:

没有答案