0

My app calls a block in tableView:didSelectRowAtIndexPath and in the block it presents a view controller. If I click the cell second time when the first click is in progress, it crashes. I've solved the problem using

tableView.userInteractionEnabled = NO;

as answered in my previous question.

It solved multiple clicking problem with table but there is another problem. I'm using ECSlidingViewController. User is able to swipe the page and select a new page from side menu while tableView:didSelectRowAtIndexPath still trying to open another page. I tried to use

 [self.view setUserInteractionEnabled:NO];

instead of

tableView.userInteractionEnabled = NO;

but it didn't work. How can I prevent swiping?

Edit:

Here is full code:

- (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;
                                                  });


                                              }

}

Community
  • 1
  • 1
zontragon
  • 780
  • 1
  • 9
  • 27
  • I think your approach is probably wrong. If you need to retrieve data after selecting the row in the table then you should do it in the new view controller, not the current. This will mean you can react immediately to user interaction and remove all of the "hacks" you are adding to try and work around it – Paulw11 Jul 23 '14 at 20:46
  • I just looked at your earlier question and indeed this was one of the answers - the better one in my opinion – Paulw11 Jul 23 '14 at 20:49
  • Actually I don't retrieve data. I use a control named EBPhotoPagesView. I call this control. If a second view is trying to open it crashes so that I want to prevent user interactions – zontragon Jul 23 '14 at 21:17
  • Are you adding that control to your current view controller or presenting a new view controller with that control? – Paulw11 Jul 23 '14 at 21:20
  • [self presentViewController:photoViewController animated:YES completion:nil]; presenting – zontragon Jul 23 '14 at 21:21
  • But you don't present immediately when then cell is selected as you mention a block? – Paulw11 Jul 23 '14 at 21:22
  • I'm editing my question to add some piece of code – zontragon Jul 23 '14 at 21:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/57877/discussion-between-paulw11-and-zontragon). – Paulw11 Jul 23 '14 at 21:40

0 Answers0