在容器视图中更新 TableView [英] Updating TableView within containerview

查看:35
本文介绍了在容器视图中更新 TableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的 UIViewController,这是一个人的个人资料页面,它显示了他们的姓名和图片.在那个 UIViewController 中,我有一个 UIContainerView 显示一个静态的 UITableView.当个人资料页面加载时,我在更新表格的单元格时遇到了一些麻烦.这是我的故事板:

I have my UIViewController, which is a person's profile page, it displays their name and picture. Within that UIViewController I have a UIContainerView that displays a static UITableView. I'm having a little trouble updating the cells of the table when the profile page loads. Here's my storyboard:

我在 UIViewController 中尝试了以下操作.

I have tried the following, within my UIViewController.

我为我的 UIView 创建了一个出口,并将 person 对象传递给它.

I created an outlet to my UIView and passed the person object to it.

在我的 UIView 中,我调用 segue 将对象传递给 UITableViewController,然后我将更新一些标签.

In my UIView I called the segue to pass the object to the UITableViewController and from there I was going to update some labels.

func prepareForSegue(segue: UIStoryboardSegue!, sender: Any?){
    if segue.identifier == "containerSegue"{
        let statsTable = segue.destination as! CollectionTableViewController
        statsTable.currentPerson = currentPerson
    }
}

我的 Segue 从来没有被调用过.我已经把它移到主 UIViewController 以防它应该从那里被调用,但又没有被调用.我用这种方法做错了什么?

My Segue is never called though. I have moved it to the main UIViewController in case it should be called from there, but again not called. What am I doing wrong with this approach?

推荐答案

假设您已将 Segue Identifier 设置为containerSegue",您应该在Stats"视图控制器中获取它.

Assuming you have set the Segue Identifier to "containerSegue" you should get it in your "Stats" view controller.

您在使用 Swift 3 吗?您可能只是 func 定义错误:

Are you using Swift 3? It's possible you just have the func definition wrong:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "containerSegue" {
        let statsTable = segue.destination as! CollectionTableViewController
        statsTable.currentPerson = currentPerson
    }
}

应该有效.

这篇关于在容器视图中更新 TableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆