gpt4 book ai didi

ios - Swift:为 UITableViewController 子类使用变量

转载 作者:行者123 更新时间:2023-11-28 06:54:14 25 4
gpt4 key购买 nike

拿这行代码:

让 controller = storyboard.instantiateInitialViewController() 作为! MyCustomTableViewController

现在我想用一个变量替换 MyCustomTableViewController,如下所示:

var customTVC: UITableViewController
customTVC = MyCustomTableViewController
让 controller = storyboard.instantiateInitialViewController() 作为!自定义TVC

编译器提示:

Cannot assign a value of type customTVC.Type to type UITableViewController in coercion

我收到了消息,但是正确执行此操作的方法是什么?显而易见的一点是,子类的确切种类可能会有所不同,我只想实现该 Controller 引用一次。

最佳答案

如果我正确理解你的问题,你可以使用typealias:

typealias customTVC = MyCustomTableViewController
let controller = storyboard.instantiateInitialViewController() as! customTVC

查看文档 here在“类型别名”下。

关于ios - Swift:为 UITableViewController 子类使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34142527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com