ios - 使用 Swift 以编程方式更改 View - 不起作用

标签 ios swift

我有以下旨在更改 View 的代码。当我的“UITableViewRowAction”被选中并打算导航到不同的 UITableViewController 时,将执行此代码。但是,我收到以下错误,我不明白我做错了什么。

 let storyBoard: UIStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
 let selectFolderViewController = storyBoard.instantiateViewController(withIdentifier: "SaveArticleTableViewController") as! SaveArticleTableViewController
 self.navigationController?.pushViewController(selectFolderViewController, animated: true)

我在控制台中得到的错误是:

 Could not cast value of type 'UINavigationController' (0x106f5c898) to 'lifesci_PubMed.SaveArticleTableViewController' (0x104dbb658).

我所有的 ViewController 都嵌入在导航 Controller 中

最佳答案

很可能是你没有在 Storyboard 中正确设置 view controller 的自定义类。这是一张图片...

enter image description here

您将在该插槽中键入“SaveArticleTableViewController”。

很可能您还有其他问题,但这会让您继续前进。

关于ios - 使用 Swift 以编程方式更改 View - 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46869264/

相关文章:

ios - 自定义 UITableViewCell 的内容在编辑模式下被删除按钮重叠

c++ - 在 Release模式下在 Xcode 中编译 .cpp 期间 clang 崩溃,但在调试中正常

arrays - 自定义TableView错误

javascript - AppGyver - PhoneGap 删除加载过渡屏幕

ios - 在 iOS 中从 ABRecordID 加载 ABRecordRef

ios - 在应用程序委托(delegate)中全局更改色调后临时更改色调

ios - 每天按设定时间间隔触发本地通知。 (例如,每天上午 10 点至下午 6 点,间隔 5 分钟)

ios - 对 block 内弱引用的强引用

objective-c - 封装特定类型画笔在Objective-C中的绘制方式

ios - 如何解码对象数组并从用户默认值中检索它?