ios - 在堆栈上嵌入 2 个或更多导航 Controller

标签 ios uitableview swift uinavigationcontroller viewcontroller

我试图在同一个堆栈上获取两个导航 Controller ,并在它们之间传递数据,最好的解释方式是通过下图。

storyboards

第一个导航 Controller (最左边的那个)连接到 TabBarController。

当将数据从 TEST tableViewController 传递到第二个 tableViewController (subDuaList) 时,我在 prepareForSegue 方法的代码中遇到错误 ...

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        var subDua:subDuaList = segue.destinationViewController as subDuaList //ERROR OCCURS HERE

        var Index = tableView!.indexPathForSelectedRow()?.row

        var duaIndex = 130 - Index!

        var selectedDua = self.packagedChapter[duaIndex]
        println(selectedDua.title)

        subDua.duaArray = selectedDua.dataArray
        subDua.rowPressed = Index

    }

在导航 Controller 中嵌入第二个 tableViewController 的原因是我可以将栏按钮项添加到导航栏。

最佳答案

编辑

正如@Shim 评论的那样,我的回答只是解释了错误输出的原因,但没有说明我在对您的问题的评论中已经说过的事情:

不允许在现有导航堆栈上推送 UINavigationController。因此,您应该删除第二个导航 Controller ,并将 UIBarButtonItem 添加到 subDuaList View Controller 的 navigationItem


错误的原因是,segue.destinationViewController 是第二个 UINavigationController 而不是 subDuaList View Controller 。

如果允许,您可以按如下方式修复您的代码,方法是替换:

var subDua:subDuaList = segue.destinationViewController as subDuaList //ERROR OCCURS HERE 

var navCtrl:UINavigationController = segue.destinationViewController as UINavigationController 
var subDua:subDuaList = navCtrl.childViewControllers[0] as subDuaList

关于ios - 在堆栈上嵌入 2 个或更多导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27425490/

相关文章:

ios - 为 Mac Catalyst 构建时扩展不可用

ios - rawValue 属性在哪里?

iphone - UITableView中customCell隐藏一个按钮也隐藏其他单元格的下一个按钮

iphone - TableView : Data overlapped while delete the row

ios - 应用程序在 viewWillDisappear() 上随机崩溃

ios - [非 A 类型保留] : message sent to deallocated instance, objective-c

ios - 实现不完整

ios - UITableViewCell 不显示

ios - `reloadRowsAtIndexPath` 崩溃

ios - 如何使用 UIImagePickerControllerDelegate 在 vi​​ewDidLoad 上启动相机?