1

I am creating an app that allows the user to see a random quote everyday. In this app, the user is asked 3 questions before being able to actually use the app. The last question is a simple "What is your favorite category/topic". With this prompt, the user will tap a cell and be brought to a Tab Bar Controller with the first "Child" view controller being the quote itself.

Problem: I want the user to be able to tap a UITableViewCell and the one they tap effects which TabBarController they are brought to.

enter image description here

That is the photo with the errors I am running into so far. Here is the code.

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
    }
        
   
    
    
}

Eventually, there will be more topics, meaning more segues. But for now, I'm starting with two

The segues for each TabBarController are: "bookSegue" "businessSegue"

The Tab Bars are: "bookQuoteTabBar" and "businessQuoteTabBar"

The First "Child" View controllers are: "bookQuoteScreen" "businessQuoteScreen"

Should I have written something else? Did I correctly name the Segues, identities, and classes of each object? If you need more information or references, comment what I should add and I will add it within minutes. Thank you in advance!

---------Recent edits---------

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!
...
}

enter image description here

DrPepperGrad
  • 361
  • 1
  • 4
  • 17

1 Answers1

0

The errors in your screenshot ("Use of undeclared type ....") indicate that Xcode does not recognise bookQuoteScreen and businessQuoteScreen as valid types. In the highlighted lines, eg.

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

the type (specified after "as? ") must match up with the class name defined in your .swift files. Check very carefully that the names used match the class names (presumably) defined in "BusinessQuoteScreen.swift" and "BooksQuoteScreen.swift". Without seeing the contents of those files, I can't be certain, but I suspect the leading character needs to be upper case (it should be for class names), and you might need an "s" in "BooksQuoteScreen":

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

and

let businessQuoteScreen = businessQuoteTabBar.viewControllers?[0] as? BusinessQuoteScreen
pbasdf
  • 21,386
  • 4
  • 43
  • 75
  • I am still getting the same error, even when they all seem to match. Am I missing an area? Could you explain how to set it up generally? Maybe I can redo this and not mess up the second time around. Others may be able to learn from it too, so that they don't do the dumb mistake I did. – DrPepperGrad May 07 '16 at 17:38
  • @JNorris If you have double checked the names, etc, it is possible that Xcode does not realise that your two swift files should be included in the "target". You can check: select each file in the list on the left hand side, then on the right hand side, click on the square-isa icon (above "Quick Help") to show the File Inspector. Further down on the RHS Xcode will show "Target membership" - what names are listed there, and are they ticked? – pbasdf May 07 '16 at 17:48
  • The first one says "Quote Daily", it has a check mark. The second says "Quote DailyTests", not checked. The last says "Quote DailyUITests", also not checked. It's the same for both files – DrPepperGrad May 07 '16 at 17:57
  • OK, so that's as it should be. Can you edit your post to include the class definitions from those two files? – pbasdf May 07 '16 at 18:04
  • Okay. I posted it, but now it seems that the error of "BusinessQuoteScreen" is gone. So that's half the battle. – DrPepperGrad May 07 '16 at 18:18
  • @JNorris Some progress, at least. And you've included the extra "s" in `.... as? BooksQuoteScreen`? – pbasdf May 07 '16 at 18:23
  • Yes. It says "BooksQuoteScreen". – DrPepperGrad May 07 '16 at 18:28
  • I'm running out of ideas, but one last try: delete that line and retype it from scratch. As you start to type `Book...` Xcode should offer a list of known names. Does "BooksQuoteScreen" appear in that list? – pbasdf May 07 '16 at 18:35
  • Yes it does. When I retyped it, it took away both of the errors and gave me 2 new caution(yellow) errors. "Initialization of immutable value 'booksQuoteScreen' was never used; consider replacing with assignment to _ or removing it". I edited my question for you to see it. – DrPepperGrad May 07 '16 at 18:39
  • That is just to warn you that you have created a local variable, `bookQuoteScreen`, but you haven't used it. Normally you might set a property on `bookQuoteScreen` at this point. But if you don't need to, you can just delete the line completely (or just ignore the warning). – pbasdf May 07 '16 at 18:46
  • I'm getting the SIGABRT error. What if I used "if (indexPath.row == 0) " ? How would that work? – DrPepperGrad May 08 '16 at 19:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111360/discussion-between-pbasdf-and-j-norris). – pbasdf May 08 '16 at 20:39