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

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

问题描述

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

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)

然后我可以看到正确的数据被放入数组中(我在这个场景中将其设为全局),但表没有在视图控制器中更新.

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你要做的就是点击storyboard中的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"

https://www.dropbox.com/s/qfd9jqeos7ueq1w/Screen%20Shot%202015-06-25%20at%207.40.46%20PM.png?dl=0

这篇关于根视图控制器 Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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