Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.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 在主细节应用程序中查看和弹出UITableViewCell_Ios_Swift_Uikit - Fatal编程技术网

Ios 在主细节应用程序中查看和弹出UITableViewCell

Ios 在主细节应用程序中查看和弹出UITableViewCell,ios,swift,uikit,Ios,Swift,Uikit,我有一个来自RayWenderlich的示例应用程序:-请获取 在这个项目中,我们在一个表视图中有一个糖果列表,如果我们点击一行,我们将获得该糖果的详细信息视图。为了使“详细信息”视图正常工作,我们正在使用选定的糖果设置DetailViewController的detailCandy属性 我想添加peek和pop功能只是为了好玩。我尝试了简单的方法:只是在故事板中启用预览和提交片段,然后等待它开箱即用。它确实使用适当的segue调用了preparefor:sender:方法,但不幸的是,我似乎无

我有一个来自RayWenderlich的示例应用程序:-请获取

在这个项目中,我们在一个表视图中有一个糖果列表,如果我们点击一行,我们将获得该糖果的详细信息视图。为了使“详细信息”视图正常工作,我们正在使用选定的糖果设置DetailViewController的detailCandy属性

我想添加peek和pop功能只是为了好玩。我尝试了简单的方法:只是在故事板中启用预览和提交片段,然后等待它开箱即用。它确实使用适当的segue调用了preparefor:sender:方法,但不幸的是,我似乎无法从tableView本身确定selectedCandy

tableView的indexPathForSelectedRow为零。 我可以使用私有API快速修复来解决此问题,方法是获取以下属性:tableView.valueforKey:pendingSelectionIndexPath as!索引 我知道我可以在UIViewControllerPreviewingDelegate的帮助下从代码中手动实现peek&pop,我的问题就解决了。 有人知道如何轻松优雅地解决这个问题吗?

使用tableView.indexPathfor:sender as!在preparefor:sender:中的UITableViewCell执行作业

这是我的备考者:发件人:的样子:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {

    var indexPath = tableView.indexPathForSelectedRow
    if indexPath == nil {
        indexPath = tableView.indexPath(for: sender as! UITableViewCell)
    }

  if let indexPath = indexPath {
    let candy: Candy
    if isFiltering() {
      candy = filteredCandies[indexPath.row]
    } else {
      candy = candies[indexPath.row]
    }
    let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
    controller.detailCandy = candy
    controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
    controller.navigationItem.leftItemsSupplementBackButton = true
  }
 }
}

它会检查单元格是否被选中,或者用户是否在偷看,并进行相应调整。

乐意帮助: