0

I have recently started to learn iOS with obj-c from "iOS Programming The Big Nerd Ranch Guide 4th Edition". This edition was released in 2014 and is written with Xcode 5.

I am trying to make a simple app with two buttons and two labels. The labels are connected to two arrays and when a button is pressed an object from the corresponding array is shown in the corresponding text label (it's the Quiz app in chapter 1).

I created the project as a Single View app in Xcode 6, and put all my objects in the view controller class. I have two labels two buttons two arrays and an int to keep track of the object that has to be displayed from the array.

In the book it says that I should initialize the arrays in the initWithNibName method. I tried that but for some reason it never gets called. So I changed the initialization of the arrays to the init method. They initialize fine but when they are called from another method they are nil. Do you have any idea why this is happening?

The second issue I'm having is that I can't manage to get the contents of the storyboard on screen. It says that I'm supposed to make an instance of the ViewController inside the AppDelegate and make it the root window controller but all I get is a white window (or black in case I don't set the color).

UPDATE: I changed the intialization of the arrays from the init method to the viewDidLoad method and now they seem to be working fine. Nothing on the screen though.

Alex Craciun
  • 473
  • 1
  • 3
  • 13
  • 1
    You should probably format your question so it's readable, and post your code, because talking about doesn't do much good without seeing it. – l'L'l Aug 11 '15 at 14:44

2 Answers2

2

It sounds like you're initializing your UIViewController from the app delegate AND a storyboard. If you create a new project in XCode, a "Single view application", you won't have to touch the app delegate at all in order to get something on the screen.

I believe both your problems are related to this, since it sounds like you're seeing an empty UIViewController on the screen (the one you create in the app delegate)

As for the initialization of your array, viewDidLoad is a popular place to do this.

Mattias
  • 2,266
  • 2
  • 15
  • 16
  • Thank you. The 'viewDidLoad' method worked. Now I've got to figure how to get everything on the screen. – Alex Craciun Aug 11 '15 at 15:20
  • Remove the viewcontroller-creation/"root window stuff"-code from the app delegate. Add the components in the storyboard and run the app – Mattias Aug 11 '15 at 15:24
  • Thanks. I removed that stuff and I also disabled size classes. After that I just had to select the proper screen size and it worked fine. Hope I'll learn how to resize properly soon so I won't have this issue again. – Alex Craciun Aug 11 '15 at 17:27
0

If you are using storyboards, the method initWithNibNameOrNil will not be called. In the BNR book, it teaches you to use XIB files, which do use this method. If you are trying to follow the tutorials, I would suggest using XIB files.

For use of a book, I would suggest downloading whatever version of Xcode is being used for that book -- otherwise you will be running into a lot of confusing problems while learning.

If you would like to download previous version of Xcode, refer to this post: How to download Xcode DMG or XIP file?

Community
  • 1
  • 1
ecatalano
  • 687
  • 1
  • 4
  • 17
  • Thanks but I'd rather stick with the latest version of Xcode. I mean if I learn older versions of Xcode I'll still have to learn the newer ones at some point. – Alex Craciun Aug 11 '15 at 15:18