【问题标题】:how to pass the data to other UIViewcontroller in swift如何快速将数据传递给其他 UIViewcontroller
【发布时间】:2018-04-03 08:20:17
【问题描述】:

我正在 swift3 中使用 mvvm 开发一个项目。它在没有情节提要的情况下使用。那么,如何从 tableview 给出 didSelectRowAt。

【问题讨论】:

标签: ios


【解决方案1】:

将 SomeViewController 视为您要跳转到的视图控制器,“someViewController”是该视图控制器上的标识符。

在 tableview didSelectRowAtIndexPath 调用 self.performSegueWithIdentifier

func tableView(tableView: UITableView, didSelectRowAtIndexPath 
   indexPath: NSIndexPath) {
   self.performSegueWithIdentifier("someViewController", sender: 
   indexPath);
}

在 prepareForSegue 方法中,只需识别 SomeViewController 的标识符并将其添加为destinationViewcontroller。

override func prepareForSegue(segue: UIStoryboardSegue!, sender: 
  AnyObject!) {
  if (segue.identifier == "someViewController") {
     let controller = (segue.destinationViewController as! 
     UINavigationController).topViewController as! SomeViewController
  }
}

【讨论】:

猜你喜欢
  • 2021-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多