根视图控制器Swift [英] Root View Controller Swift

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

问题描述

我的应用程序委托中有一个函数,该函数将一个项目追加到名为ViewController.swift的文件中的数组中,然后我想在该文件中重新加载表视图.我尝试这样做:

I have a function in my app delegate which appends an item to an array in my a file named ViewController.swift, and then I want to reload a tableview in that same file. I attempt to do so like so:

let vc = ViewController()
let navigationController = UINavigationController(rootViewController: vc)
window!.rootViewController = navigationController
println(vc.messages)

//1        vc.messages.append(message.data.message as! String)
//2        vc.MessageTableView?.reloadData()

编号1,2的行是我设置断点的地方.它似乎在编号2的行后中断.

The lines numbered 1,2 are where I set breakpoints. It appears to break after line numbered 2.

我得到的确切错误是

致命错误:解开可选值时意外发现nil

fatal error: unexpectedly found nil while unwrapping an Optional value

我相信我的问题是我错误地设置了根视图控制器.

I believe my problem is that I am setting the root view controller incorrectly.

将窗口声明为顶部.

如果我这样运行我的代码:

If i run my code like this:

    let vc = ViewController()
    messages.append(message.data.message as! String)
    vc.MessageTableView?.reloadData()
    println(messages)

然后我可以看到将正确的数据放入了数组(在这种情况下我将其设置为全局),但是该表在View控制器中没有得到更新.

Then I can see that the correct data is put into the array (Which i made global for this scenario) but the table does not get updated in the View controller.

推荐答案

如果您想让viewcontroller成为rootviewcontroller,那么您要做的就是单击情节提要中的viewcontroller,然后在实用程序中->属性检查器->检查框是初始视图控制器"

if you want you viewcontroller to be the rootviewcontroller al you have to do is click on the viewcontroller in storyboard and then in the utilities-> attributes inspector -> check the box "is initial view controller"

查看全文

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