ios - 如何更改 ContainerView 中嵌入 TableVeiw 中的变量?迅速
问题描述
class MyView:UIViewController{
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print(segue.destination)
let distinationVC = segue.destination as? MyTableController
distinationVC?.topConstaints.constant = 0
}
}
class MyTableController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var topConstaints: NSLayoutConstraint!
}
返回
print(segue.destination)
<myApp. MyTableController:0 x>
但在
distinationVC?.topConstaints.constant = 0
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
有什么我做错了吗?
我不知道如何解决这个问题
解决方案
由于尚未创建控制器视图,因此无法topConstaints
访问。prepare(for segue:)
要么创建一个CGFloat
变量,MyTableController
然后更改你topConstaints
的变量,viewDidLoad
要么立即调用let _ = distinationVC.view
以let distinationVC = ..
触发 distinationVC's loadView
。
推荐阅读
- scala - Akka - 如何检索对分片区域中实体的子角色的引用?
- linux - 使用 shell 脚本获取多行 XML 中的标记值
- php - 如何提供基于 2 个数组的文本框列表和文件输入文本框
- python - 如何从弹性搜索查询中获得准确的搜索结果
- r - 编写一个函数返回一个对应的值
- oracle - Oracle PL/SQL 为动态 SQL 交换 for 循环,协助语法更改
- java - AWS ECS 任务进入挂起状态
- reactjs - React - 基于计数的动态输入字段
- python - 迭代比较两个文件并建立父子关系的Python逻辑
- javascript - 具有高斯模糊的剑道 UI 模态