因为我不想让 topContainer 稍后显示。我从 viewDidLoad
的 super View 中删除了它。
override func viewDidLoad() {
super.viewDidLoad()
//somecode
topContainer.removeFromSuperview()
//somecode
}
恢复它的功能是什么?
我尝试了 insertSubview
但不知道这是否是正确的方法,如果是这样,我如何获取此 func 第二个参数的 subview 索引?我无法在右侧面板中找到它。
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//...
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> //...
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
switch (indexPath.row) {
case 0:
//<------------ I need to show it again here
default:
break
}
}
最佳答案
如果您不希望 View “显示到稍后”,那么您需要做的就是将其hidden
设置为true
。这样它就不会失去它在 View 层次结构中的位置,也不会被删除。
当你想显示 View 时,myView.hidden = false
。
关于ios - Swift 2.1 与 removeFromSuperview 相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34214639/