UITableView 需要双击 - 但不是第一次
UITableView requires double tap - but not first time
我有一个 UITableView,其中包含您可以点击的单元格。
当您点击时,一些操作是 运行,但这在本文中并不重要。我第一次按下时,它会正确处理水龙头。第二次是 运行ning 代码,但是所有视图更新(如显示 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;
}
}
}
SelectionStyle 设置为 None,但我们将其更改为其他内容,这解决了问题。
单击 TableViewCell 本身。
在您的属性部分找到:"Selection"
设置为:Blue/Grey/Default.
我有一个 UITableView,其中包含您可以点击的单元格。 当您点击时,一些操作是 运行,但这在本文中并不重要。我第一次按下时,它会正确处理水龙头。第二次是 运行ning 代码,但是所有视图更新(如显示 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;
}
}
}
SelectionStyle 设置为 None,但我们将其更改为其他内容,这解决了问题。
单击 TableViewCell 本身。 在您的属性部分找到:"Selection" 设置为:Blue/Grey/Default.