2

In my application, I'm using a UITableView for showing the reservations for a doctor on a specific day. With the help of two gesture recognizers I'm able to swipe over the table view to show the next (swipe right to left)/previous(swipe left to right) day.

When I swipe, I check if I've already loaded the reservations from the database and if they aren't loaded I show an alertview with an activity indicator to show the user it's loading.

When the loading is done, I dismiss this alertview and show an animation which flips the view (UIViewAnimationTransitionFlipFromLeft) and show the new day.

Now the issue is: after the view is flipped, didSelectRowAtIndexPath: is not getting called when I tap a cell for the first time. But if I tap it again, the method fires. It seems that I first have to tap anywhere in the view to "make the view active". Is the alertview maybe still present on top of the tableview somehow?

The code to handle the swipe from left to right:

-(void)handleSwipeR
{
//Disable user interaction.
[table setUserInteractionEnabled:NO];
[self.navigationController.navigationBar setUserInteractionEnabled:NO];

if (swipeEnabled == YES) {
    swipeEnabled = NO;

    //we use the curIndex to check if it is necessary to get new data.
    if (curIndex > 0)
    {
        //Commit the animations and reload all the data.
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:table cache:NO];
        [UIView setAnimationDuration:1];
        [UIView setAnimationDidStopSelector: @selector(animationFinished:finished:context:)];
        [UIView commitAnimations];
        curIndex --;
        [Database setCurDate:[keys objectAtIndex:curIndex]];
        [table reloadData];
    }else {
        //We show a loading screen until the new reservation data is collected.
        loading=[[UIAlertView alloc] initWithTitle:loadingText message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
        loadingInd=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [loadingInd startAnimating];
        [loadingInd setFrame:CGRectMake(125, 60, 37, 37)];
        [loading addSubview:loadingInd];
        [loading show];

        [Database setCurAlert:loading];

        [Database setCurDate:[keys objectAtIndex:curIndex]];

        //Set startdate and enddate and get the new reservations.
        NSDate *startDate = [[Database curDate] dateByAddingTimeInterval:-60*60*24*15];
        NSDate *endDate = [[Database curDate] dateByAddingTimeInterval:-60*60*24*1];
        [Database getReservations:startDate endDate:endDate];
        [self fillVariables];
        [loading dismissWithClickedButtonIndex:0 animated:YES];
        //You get a unique id each session. If you logged in at another location, the session id will change. So the first one is invalid. So we first check if the session id is still valid.
        if (![Database sessionExpired]) {
            //If there aren't found any reservations for the next two weeks. Show an Alertview.
            if ([Database elementFound] == NO) {
                reservationSearch = 2;

                alertNoResMessage = [NSString stringWithFormat:[LanguageStrings resListNoResMessageSwipeR],reservationSearch];

                //sleep(1);
                alertNoRes= [[UIAlertView alloc]initWithTitle:alertNoResTitle message:alertNoResMessage delegate:self cancelButtonTitle:alertNoResButtonYes otherButtonTitles:alertNoResButtonNo, nil];

                alertNoRes.tag = 201;
                [alertNoRes show];
            }else {
                //Commit the animations and reload all the data.
                curIndex = [keys indexOfObject:[Database curDate]];
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDelegate:self];
                [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:table cache:NO];
                [UIView setAnimationDuration:1];
                [UIView setAnimationDidStopSelector: @selector(animationFinished:finished:context:)];
                [UIView commitAnimations];
                curIndex --;
                [Database setCurDate:[keys objectAtIndex:curIndex]];
                [table reloadData];
            }
        }
    }
    swipeEnabled = YES;
}
}

//Enable all user interaction when the animation is finished.
- (void) animationFinished:(NSString *)animationID finished:(BOOL)finished context:  (void *)context{
[table setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
swipeEnabled = YES;
}

I've been looking it up for a while now and I don't seem to find the answer for this, so your help would be appreciated.

Monolo
  • 18,205
  • 17
  • 69
  • 103
Alex
  • 21
  • 2
  • have you tried writing some code to check what object is the first responder after you flip back? If you do a search on "how to check first responder" you'll a bunch of pre-made code to help accomplish it easily. – DBD Sep 19 '12 at 13:40
  • It seems non of the objects on the screen have the status first responder. I've been testing and rewriting my code and it seems that when I leave out the loading alert view everything works correctly, so the problem doesn't lie at the animation part... – Alex Sep 19 '12 at 14:34
  • Try setting your `UITableView` to be first responder on on `viewWillAppear` and see if it fixes the issue. – DBD Sep 19 '12 at 14:39
  • The UITableView won't become first responder. I type this in in viewWillAppear: [table becomeFirstResponder]; NSLog(@"%d", [table isFirstResponder]); The log says: 0 – Alex Sep 19 '12 at 14:55
  • Hmm... very interesting. It does appear to be a first responder issue, but I have no idea why it wouldn't become first responder. I've never run into this myself because I don't user `UIAlertView`s for loading. I mostly use a `UIView` with a partial transparent background to fade out the rest of the screen and a loading spinner/message, but either way should be valid! – DBD Sep 19 '12 at 15:20
  • I'll try your solution then.. I've noticed that the 'UIAlertView' isn't added as a subview on the current stack, but rather as a subview of a 'UIAlertNormalizingOverlayWindow', it maybe has something to do with that window? – Alex Sep 20 '12 at 07:03
  • Might this be an instance of http://stackoverflow.com/questions/2106292/uitableview-didselectrowatindexpath-not-being-called-on-first-tap? – edsko Jan 30 '13 at 15:03

0 Answers0