[英]tableview appear to be nil in ViewController when it's root by a navigation controller [SWIFT 3]
I'm having an issue with my current project. 我目前的专案有问题。 At the beginning my main focus was to create a overlay button in a TableViewController but i saw that it was more simple to use a ViewController and set on it a tableView :
一开始,我的主要重点是在TableViewController中创建一个叠加按钮,但我发现使用ViewController并在其上设置tableView更简单:
class MemoList : UIViewController, UITableViewDataSource, UITableViewDelegate{
@IBOutlet weak var myTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
myTableView.delegate = self
#datasource is linked manually in the StoryBoard
...
}
}
When this View Controller is set as the initial controller, everything work fine but in my case, when the projet is rooted by a navigation controller, the tableview appears to be nil in the context of the 'Memolist' (when pushing on it). 当将此View Controller设置为初始控制器时,一切正常,但就我而言,当projet由导航控制器作为根目录时,在“记事簿”的上下文中(推入时)表视图似乎为零。
Do you have any idea about this issue ? 您对这个问题有任何想法吗? And how can I solve it ?
我该如何解决呢?
Thanks, 谢谢,
For me the problem was that I used 对我来说,问题是我曾经
present(myViewController, animated: true, completion: nil)
After I tried to use segue and 在我尝试使用segue和
performSegue(withIdentifier: "myIdentifier", sender: self)
it worked properly and tableView was no longer nil. 它工作正常,tableView不再为零。
Why did I have this problem: When you use present()
, you initialise the View Controller
from code and it doesn't watch on your Storyboard
. 为什么会有这个问题:当您使用
present()
,您会从代码初始化View Controller
,并且它不会在Storyboard
上监视。 When you use segues
, it uses the Storyboard
and of course see all you did in your Interface Builder
当您使用
segues
,它将使用Storyboard
并且当然会看到您在Interface Builder
所做的一切
You also can: 您还可以:
UIStoryboard(name: "StoryboardName", bundle: nil).instantiateViewController(withIdentifier: "ViewControllerId")
This creates view controller from Storyboard, so that tableView is initialized now 这将从Storyboard创建视图控制器,以便立即初始化tableView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.