当我尝试调试此代码时,发生了最奇怪的事情:
- (IBAction)showNextMeal:(id)sender {
unsigned int flags = NSHourCalendarUnit | NSMinuteCalendarUnit;
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:flags fromDate:[NSDate date]];
NSDate* currentTime = [calendar dateFromComponents:components];
NSArray* todays = [self MealsForDay:DayOfWeek];
int segueid = 0;
for (int i = 0; i < 3; i++) {
NSDate * startTime = [calendar dateFromComponents:[calendar components:flags fromDate:[[todays objectAtIndex:i] End]]];
NSComparisonResult c = [currentTime compare:startTime];
if (c == NSOrderedAscending) {
segueid = i;
break;
}
}
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:segueid inSection:0];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self performSegueWithIdentifier:@"MealSegue" sender:self];
}
代码运行良好,直到倒数第三行 ( NSIndexPath* indexPath
),然后跳回int segueid = 0
并再次运行。在 if 弄清楚自己之后,iphone 会执行两个 segues 到同一个地方。
我已经截屏了调试,所以你可以准确地看到我在说什么。
http://www.youtube.com/watch?v=3SR-O5Xhsqk
为什么计算机在代码中跳跃,为什么它会在同一个地方执行两个 segues?