Ios 当我选择时,在时间之后取消选择单元格

Ios 当我选择时,在时间之后取消选择单元格,ios,objective-c,iphone,uitableview,nstimer,Ios,Objective C,Iphone,Uitableview,Nstimer,我想取消选择我的tableview单元格。但5秒后自动选择。我试着这样做 [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector ([tableView deselectRowAtIndexPath:indexPath animated:YES]) userInfo:nil repeats:NO]; 在这个方法中,-(void)tableView:(UITableView*)tableView没有选择

我想取消选择我的tableview单元格。但5秒后自动选择。我试着这样做

[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector ([tableView deselectRowAtIndexPath:indexPath animated:YES]) userInfo:nil repeats:NO];
在这个方法中,
-(void)tableView:(UITableView*)tableView没有选择rowatindexpath:(nsindepath*)indepath
,但是XCode说我失败了

请帮忙
谢谢大家。

这可能必须在主线程上执行。将其更改为分派,它将自行进行排序

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
         [tableView deselectRowAtIndexPath:indexPath animated:YES];
});

这将在5秒后调度调用,然后在主线程上执行取消选择。

这里不需要dispatch\u async,因为dispatch\u after将在提供的队列(主队列)上执行。您应该创建一个指向tableView的弱指针,以便在您离开tableView所在的场景并需要取消分配它时不会泄漏内存。