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.