Tôi gắn một UISwipeGestureRecognizer
đến một UITableViewCell
trong phương pháp cellForRowAtIndexPath:
như vậy:UIGestureRecognizer và UITableViewCell vấn đề
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
gesture.direction = UISwipeGestureRecognizerDirectionRight;
[cell.contentView addGestureRecognizer:gesture];
[gesture release];
}
return cell;
}
Tuy nhiên, phương pháp didSwipe
luôn nhận được gọi là hai lần trên swipe thành công. Ban đầu tôi nghĩ rằng điều này là do các cử chỉ bắt đầu và kết thúc, nhưng nếu tôi đăng nhập ra gestureRecognizer bản thân, họ đều trong "Đã kết thúc" nhà nước:
-(void)didSwipe:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"did swipe called %@", gestureRecognizer);
}
Console:
2011-01-05 12:57:43.478 App[20752:207] did swipe called <UISwipeGestureRecognizer: 0x5982fa0; state = Ended; view = <UITableViewCellContentView 0x5982c30>; target= <(action=didSwipe:, target=<RootViewController 0x5e3e080>)>; direction = right>
2011-01-05 12:57:43.480 App[20752:207] did swipe called <UISwipeGestureRecognizer: 0x5982fa0; state = Ended; view = <UITableViewCellContentView 0x5982c30>; target= <(action=didSwipe:, target=<RootViewController 0x5e3e080>)>; direction = right>
tôi thực sự thực sự không biết tại sao. Tôi đã cố gắng kiểm tra rõ ràng trạng thái kết thúc, nhưng đó không phải là sự giúp đỡ vì cả hai đều đến như "Kết thúc" dù sao ... Có ý tưởng gì không?
Cảm ơn! Điều đó khiến nó ngừng bắn hai lần! :) – mootymoots
Cảm ơn, điều này đã giúp, nhưng tôi thấy một cái gì đó kỳ lạ - sau khi swiping tôi cần phải bấm hai lần nếu tôi muốn chọn hàng. Lần đầu tiên không có gì, và các cuộc gọi thứ hai didSelectRow ... Bất kỳ ai nhìn thấy điều này? –
@OdedBenDov Tôi tin rằng đó là do trình nhận dạng cử chỉ gây ra, tôi đã có hành vi lạ đối với lựa chọn ô xem bảng khi tôi thêm trình nhận dạng cử chỉ và quên xóa trong phương thức chỉnh sửa cuối của trường văn bản (chế độ xem phụ của ô xem bảng), có thể được điều này có thể hoạt động như một đầu mối để giải quyết vấn đề của bạn, thêm chi tiết [tại đây] (http://stackoverflow.com/questions/9939509/strange-behavior-did-select-row-touch-not-responding-for-uitableviewcell) –