The project should work fine in the current Xcode and iOS release. (I did not check it with the iOS 6 beta)
The template for the MasterDetail project changed and the author did not update the project to reflect these changes. You can comment out the code
Code:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
since this is not used.
If you try to copy the books code directly (I don't have the book, but am referring to the downloadable project), assuming all of your classes are named as in the book, you should have no problems. One line is redundant since the assignment is handled in the AppDelegate class.
Code:
self.detailViewController =
(MasterDetailDetailViewController *) [[self.splitViewController.viewControllers lastObject] topViewController];
can be omitted since the assignment is done in the AppDelegate's
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method.
the complete -viewDidLoad would be
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
//â-initialize the arrayâ-
listOfMovies = [[NSMutableArray alloc] init];[listOfMovies addObject:@"Training Day"];[listOfMovies addObject:@"Remember the Titans"];[listOfMovies addObject:@"John Q."];[listOfMovies addObject:@"The Bone Collector"];[listOfMovies addObject:@"Ricochet"];[listOfMovies addObject:@"The Siege"];[listOfMovies addObject:@"Malcolm X"];[listOfMovies addObject:@"Antwone Fisher"];[listOfMovies addObject:@"Courage Under Fire"];[listOfMovies addObject:@"He Got Game"];[listOfMovies addObject:@"The Pelican Brief"];[listOfMovies addObject:@"Glory"];[listOfMovies addObject:@"The Preacherâs Wife"];
self.navigationItem.title = NSLocalizedString(@"Movies", @"Movies");
//---
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
//---
// Do any additional setup after loading the view, typically from a nib.
// self.navigationItem.leftBarButtonItem = self.editButtonItem;
//
// UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)] autorelease];
// self.navigationItem.rightBarButtonItem = addButton;
}
}
Of course the commented out lines can just be deleted.
One problem with this (for me) is the fact that the author has the tableView select a row, without having the detailView reflect the selection. A better approach would be
Code:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
//---
[self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
}
If you have further problems, be specific about what errors are being generated, and your issues should be able to be sorted out.
Bob