【问题标题】:Objective-C to Swift Navigation not workingObjective-C 到 Swift 导航不起作用
【发布时间】:2014-12-17 18:46:00
【问题描述】:

我正在将一些代码从 Objective-C 翻译成 Swift,但有些东西不起作用。下面的代码应该切换视图并传递一个字符串,但是,当一个单元格被点击时没有任何反应。我已经在 Storyboard 中嵌入了带有 NavigationViewController 的两个 ViewController。

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

        var dvc : TemplateViewController = self.storyboard?.instantiateViewControllerWithIdentifier("TemplateViewController") as TemplateViewController
        dvc.tweet = self.templateList?.objectAtIndex(indexPath.row) as NSString
        self.navigationController?.pushViewController(dvc, animated: true)

}

【问题讨论】:

  • 您确定要在单元格取消选择而不是选择时执行该操作吗?如果你已经实现的方法,请查看名称 v
  • ^ 是的,没错!盲目使用自动填充
  • 你检查过dvcself.navigationController不是null吗?
  • @user3330259 修复方法名称是否解决了问题?如果是这样,Abizem 可能需要将他的评论推广为答案,以便您接受它。

标签: uitableview swift uiviewcontroller uinavigationcontroller


【解决方案1】:

您需要在 TemplateViewController 中显式编写一些方法。按照这个答案 Instantiate and Present a viewController in Swift

【讨论】:

  • 他在他的示例尝试中得到了所有相关部分。最有可能的罪魁祸首是他的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多