首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UITableView从其他视图控制器添加行

UITableView从其他视图控制器添加行
EN

Stack Overflow用户
提问于 2018-05-29 23:32:56
回答 3查看 400关注 0票数 1

我有两个视图控制器,一个有3个表视图,另一个控制器,我有一个uitextfield和在文本字段中输入的文本,我想把它添加到另一个视图控制器的一个名为ScheduleTableView的表视图中。以下是我的代码,但在vc.ScheduleTableView.beginUpdates()处展开可选值时,我收到错误:意外发现nil

代码语言:javascript
运行
复制
@IBAction func addButtonTapped(_ sender: YTRoundedButton) {
   self.performSegue(withIdentifier: "secondvc", sender: self)

}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier  == "secondvc" {
        print(TitleTextField.text!)

        let vc = segue.destination as! GrowthMainViewController

        vc.ScheduleArray.append(TitleTextField.text!)
        let indexPath = IndexPath(row: vc.ScheduleArray.count - 1, section: 0)
        vc.ScheduleTableView.beginUpdates()
        vc.ScheduleTableView.insertRows(at: [indexPath], with: .automatic)
        vc.ScheduleTableView.reloadData()
        vc.ScheduleTableView.endUpdates()



        TitleTextField.text = ""
        view.endEditing(true)

  }     
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50588090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档