从 UITableView 转到 UITabBarController

Segue from UITableView to UITabBarController

我正在创建一个允许用户每天随机查看报价的应用程序。在此应用程序中,用户在能够实际使用该应用程序之前会被询问 3 个问题。最后一个问题是一个简单的“你最喜欢什么 category/topic”。有了这个提示,用户将点击一个单元格并被带到一个选项卡栏控制器,第一个“子”视图控制器就是引用本身。

问题: 我希望用户能够点击一个 UITableViewCell,他们点击的那个会影响他们被带到哪个 TabBarController。

这是我目前 运行 遇到的有错误的照片。这是代码。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    
    
    if(segue.identifier == "bookSegue")
    {
        let bookQuoteTabBar = segue.destinationViewController as! UITabBarController
        
        let bookQuoteScreen = bookQuoteTabBar.viewControllers?[0] as? bookQuoteScreen
        
        
    }
        
    else if(segue.identifier == "businessSegue") {

        let businessQuoteTabBar: UITabBarController = segue.destinationViewController as! UITabBarController
        let businessQuoteScreen = businessQuoteTabBar.viewControllers?[0] as? businessQuoteScreen
    }
        
   
    
    
}

最终,会有更多的话题,意味着更多的转折点。但现在,我从两个开始

每个 TabBarController 的 segues 是: “书序” “业务转折”

标签栏是: “bookQuoteTabBar”和“businessQuoteTabBar”

第一个“子”视图控制器是: “bookQuoteScreen” “businessQuoteScreen”

我应该写点别的吗?我是否正确命名了每个对象的 Segues、identities 和 类?如果您需要更多信息或参考资料,请评论我应该添加的内容,我会在几分钟内添加。提前致谢!

------------最近的编辑---------

BooksQuoteScreen:

import Foundation
import UIKit

class BooksQuoteScreen: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

BusinessQuoteScreen:

import Foundation
import UIKit
import Social

class BusinessQuoteScreen: UIViewController {

//============================//
//********** Outlets *********//
//============================//

let utility = Utility()
@IBOutlet weak var quoteDisplay: UILabel!
@IBOutlet weak var authorDisplay: UILabel!
@IBOutlet weak var quoteBackground: UIImageView!
...
}

您的屏幕截图 ("Use of undeclared type ....") 中的错误表明 Xcode 无法将 bookQuoteScreenbusinessQuoteScreen 识别为有效的 类型.在突出显示的行中,例如

let bookQuoteScreen = bookQuoteTabBar.viewControllers?[0] as? bookQuoteScreen

类型(在 "as? " 之后指定)必须与您的 .swift 文件中定义的 class 名称匹配。非常仔细地检查所使用的名称是否与 "BusinessQuoteScreen.swift" 和 "BooksQuoteScreen.swift" 中定义的 class 名称相匹配(大概)。没有看到这些文件的内容,我不能确定,但​​我怀疑前导字符需要大写(它应该用于 class 名称),并且您可能需要一个 "s" "BooksQuoteScreen":

let bookQuoteScreen = bookQuoteTabBar.viewControllers?[0] as? BooksQuoteScreen

let businessQuoteScreen = businessQuoteTabBar.viewControllers?[0] as? BusinessQuoteScreen