Tuesday, April 20, 2010

Pushing View Controllers

Pushing View Controllers is ridiculously simple. You can do it in 2 lines of code, but with 2 dependancies.
1) Create a navigationController object in the AppDelegate file (.h and .m).
2) You must make a UIViewController object and add its header to the View Controller header you want to push *from*
3)

PhotoListView *secondPage = [[PhotoListView alloc] initWithNibName:@"PhotoListView" bundle:[NSBundle mainBundle]];

[[self navigationController] pushViewController:secondPage animated:YES];



4) Done.

Getting back into Objective-C Programming

Thanks to Stanfords C193P course.
Some things I've found along the way:
FYI, because of the black text you'll need to copy/paste to see the entire codeblock
Convert a NSArray to C array:

NSArray *pointsArray = [PolyShape pointsForPolygonInRect:rect numberOfSides:[polygon numberOfSides]];

//count the number of objects in the array and set a matching integer

int i;

i=[pointsArray count];

//setup our C array to match the number of objects in the pointsArray...

CGPoint thePointArray[i];

//for each object in the pointsArray, set a CGPoint value, add it to the C-Array (thePointArray) in it's matching index

for (id object in pointsArray) {

CGPoint thePoint = [object CGPointValue];

i--;

thePointArray[i] = CGPointMake(thePoint.x, thePoint.y);

}