MVC (Model View Controller)

Every view has a controller, but not every controller has a view. Some special controllers, that we call controller of controllers are used in Xcode.

Connecting a view to a controller

Do some drag and drop stuff. Ctrl+click and drag UI elements to the code editor (this seems like a good idea… sarcasm intended).

IBOutlet is a keyword that allows teh view to see the code and connect to it.

IBAction has the same value as void. It is a keyword that allows the button to see the code and connect to it.

-(IBAction)firstButton:(id)sender {
}

Simulator Rotation

If you press Command+left or Command+right it will rotate the simulator. You can turn this off by unchecking “Use Autolayout” in the File Inspector for the .xib file.

The view wont rotate when the phone is upside down. Apple doesn’t want you to be playing a game or using an app with the phone upside down.

Collections

Objective-C has several different types of collections.

Collections can only contain references to objects.

NSArray

is immutable, which means it must be completely populated when it’s instantiated.

NSArray * items = [[NSArray alloc] initWithObjects:@"ruby", @"c", @"c#", nil];

nil terminal is necessary. That is how the array will know what size it will be.

To store an integer into an array:

NSArray * numbers = [[NSArray alloc] initWithObjects:[NSNumber
  numberWithInt:5]];
  [[numbers objectAtIndex:0] intValue];

NSMutableArray

Is mutable, so you can push objects into it or pop object off of it.

Controls

Controls are how we input data into our application, and view the data from our app.

Labels

The view is always controlled by the ViewController. It is the file owner.

Buttons

Touch Up Inside: When you touch the button and lift your finger off the button. Basically a click event.

44 - Magic Number

44x44 is the minimum area for when someone is tapping something.

comments powered by Disqus