在我的申请中,我使用UITableView
来显示特定日期的医生预约。在两个手势识别器的帮助下,我可以在桌面视图上滑动以显示下一个(从右向左滑动)/上一个(从左向右滑动)日。
当我滑动时,我会检查我是否已经从数据库加载了预订,如果它们未加载,我会显示一个带有活动指示的alertview,以显示用户正在加载。
加载完成后,我会关闭此提醒视图并显示一个动画,该动画会翻转视图(UIViewAnimationTransitionFlipFromLeft
)并显示新的一天。
现在的问题是:翻转视图后,第一次点击一个单元格时,didSelectRowAtIndexPath:
没有被调用。但是,如果我再次点击它,该方法会触发。似乎我首先必须点击视图中的任何位置以“使视图处于活动状态”。警报视图是否仍然存在于tableview之上?
从左到右处理滑动的代码:
-(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;
}
我一直在寻找它一段时间,我似乎没有找到答案,所以你的帮助将不胜感激。