9

我目前有一个带有两个视图控制器的应用程序。第一个是具有嵌入式表格视图的视图控制器,该表格视图具有动态单元格。第二个是带有静态单元格的表格视图控制器。如果我从选择一个动态表格的单元格到静态表格视图控制器(使用 Push 或 Modal 样式设置)添加一个转场,我可以看到转场按预期工作。但是,当我将样式更改为 Popover 时,出现以下编译错误:

Couldn't compile connection: <IBCocoaTouchOutletConnection:0x4004c75a0 <IBProxyObject: 0x400647960> => anchorView => <IBUITableViewCell: 0x400f58aa0>>

有没有其他人遇到过这个问题,或者有谁知道这个错误信息可能意味着什么?除非 Popover 中不支持静态表视图控制器,否则在编译时发生这种情况似乎很奇怪......

4

4 回答 4

15

我想出了如何做到这一点。您不能从情节提要中将其连接起来,但可以像这样以编程方式进行:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad"
                                                 bundle:nil];
    UITableViewController *detailController = [sb instantiateViewControllerWithIdentifier:@"TableSettingDetails"];

    self.popoverController = [[UIPopoverController alloc] initWithContentViewController:detailController];

    self.popoverController.popoverContentSize = CGSizeMake(320, 416);
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [self.popoverController presentPopoverFromRect:cell.bounds inView:cell.contentView
                          permittedArrowDirections:UIPopoverArrowDirectionAny
                                          animated:YES];
}

只需确保您在控制器中有对弹出框的引用,否则它将立即被处理 - 导致一些其他有趣的异常。

于 2012-09-03T00:51:23.087 回答
3

您必须为非静态单元格的 Popover 选择一个锚点。我的建议是将 UIButton 设置为不可见(自定义类型)。然后选择 Popover Segue 并将 Anchor 连接拖到该按钮。

于 2012-09-01T16:01:05.080 回答
0

我知道这个问题已经得到解答,但如果它有帮助,我有一个解决方案,同时使用 segues 保留情节提要流程。您可以在这里查看 是否可以手动执行 Popover Segue(从动态 UITableView 单元格)?

于 2013-02-14T00:02:03.893 回答
0

从 iOS 10 开始,@lehn0058 的正确且被接受的答案不再有效。这是他为 iOS 10 更新的解决方案...

override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    // *** Next line doesn't work with popover, only full screen detail
    //self.performSegue(withIdentifier: "editRow", sender: self) 
    // Hence, do it by hand...
    let sb = UIStoryboard(name: "Main", bundle: nil)
    let detailVC: MyDetailViewController = sb.instantiateViewController(withIdentifier: "itemEditor") as! MyDetalViewController
    detailVC.modalPresentationStyle = .popover
    detailVC.popoverPresentationController?.sourceView = tableView.cellForRow(at: indexPath)
    detailVC.detailItem = self.itemAtIndexPath(indexPath)

    self.present(detailVC, animated: true, completion: {})
}
于 2017-03-27T12:10:29.270 回答