【发布时间】:2015-03-06 14:48:50
【问题描述】:
我有一个 UITableView,其中包含可以点击的单元格。 当您点击时,会运行一些操作,但这在这种情况下并不重要。我第一次按下时,它会正确处理水龙头。第二次运行代码,但所有视图更新(如显示 UIAlertView 或显示新视图)都会延迟。但不被时间耽误——它在等我触摸屏幕。无论我按哪里或等待多长时间,我都必须按。而且每次都是第一次。
我的 TableView 设置为单选,而不是在触摸时显示选择。任何想法为什么会这样做?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[DetailTableViewCell class]]) {
DetailTableViewCell *detailCell = (DetailTableViewCell *)cell;
NSString *hourString = [detailCell hourString];
if (!detailCell.booking) {
NSDate *rightNow = [NSDate new];
NSDate *cellDate = [self.currentDate dateWithHour:indexPath.row andMinutes:0];
// Only allow future bookings (but allow people people to book within the hour)
if([rightNow compare:[cellDate nextHour]] == NSOrderedAscending){
[self performSegueWithIdentifier:@"roomBooking" sender:indexPath];
return;
} else {
[[[UIAlertView alloc] initWithTitle:@"Error" message:@"We currently do not allow our users make bookings in the past" delegate:nil cancelButtonTitle:@"Gotcha" otherButtonTitles:nil] show];
return;
}
} else if ([detailCell.booking hasPhoneNumber]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%ld",(long)[detailCell.booking telephone]]]];
return;
} else {
//TODO: FIND OUT IF BOOKING IS OWNED BY THE CURRENT USER
[[[UIAlertView alloc] initWithTitle:@"Booking"
message:[NSString stringWithFormat:@"You are now removing the booking at %@.", hourString]
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
@weakify(self);
[self.room removeBookingWithId:[detailCell.booking.bookingId integerValue] andCompletion:^(BOOL success, NSError *error) {
@strongify(self);
if (success) {
@weakify(self);
[self.room.location updateBookingsWithCompletion:^(BOOL success, NSError *error) {
@strongify(self);
if (success) {
[self.calendar reloadData];
}
}];
}
}];
return;
}
}
}
【问题讨论】:
-
细胞是如何构造的?单元格内是否有任何识别器或类似的东西?
-
从这里开始会是负面的。里面没有识别器,也没有我期望伤害的任何东西。有趣的是,它实际上对触摸做出了正常反应。这是 NSLogging 在正确的时间正确的东西,但只是没有显示。
-
好吧,那么只有在您删除预订后才会发生这种情况(
self.room removeBookingWithId:)?检查self.room.location updateBookingsWithCompletion:是否在主线程上执行完成块。这可能是原因。 -
无论运行什么代码都会发生这种情况。
-
你的tableView在哪里?在滚动视图中?
标签: ios objective-c uitableview uiview