Ios 尝试关闭UIViewController时出现奇怪问题
我有一个Ios 尝试关闭UIViewController时出现奇怪问题,ios,objective-c,xcode,uitableview,uiviewcontroller,Ios,Objective C,Xcode,Uitableview,Uiviewcontroller,我有一个UIViewController,它持有一个UITableView,我想在单击表的单元格时关闭UIViewController。所以我实施了这个方法: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 在这个方法中,我调用了: [self dismissViewControllerAnimated:YES completion:nil]; 出于某种原因
UIViewController
,它持有一个UITableView
,我想在单击表的单元格时关闭UIViewController
。所以我实施了这个方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
在这个方法中,我调用了:
[self dismissViewControllerAnimated:YES completion:nil];
出于某种原因,当我单击单元格时,应用程序冻结,我需要再次单击以关闭UIViewController
。我甚至在那里放了一个断点来检查它是在第一次还是第二次点击时到达的,在第一次点击时它到达了断点,然后我点击继续执行,我需要再次点击
是否有人在iOS上遇到此问题?首先,您似乎使用了
didSelectRowAtIndexPath
而不是didSelectRowAtIndexPath
。确保使用didSelect…,而不是didSelect…
其次,它冻结是因为在主线程上没有调用方法tableView:didselectrowatinexpath:
。您必须使用GCD在主队列中执行代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil];
});
}
// PLEASE TRY THIS.
[self.navigationController.popoverPresentationController];