Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 尝试关闭UIViewController时出现奇怪问题_Ios_Objective C_Xcode_Uitableview_Uiviewcontroller - Fatal编程技术网

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];