diff --git a/MasterDetail/Classes/MasterViewController.m b/MasterDetail/Classes/MasterViewController.m index 36e8187..17fb3cb 100644 --- a/MasterDetail/Classes/MasterViewController.m +++ b/MasterDetail/Classes/MasterViewController.m @@ -56,7 +56,54 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N #pragma mark Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - //do nothing at the moment + + //need to remove cell selection + [tableView deselectRowAtIndexPath:indexPath animated:NO]; + + //if there is now split view controller this controller + //is not used as a master controller + if(self.splitViewController == nil) + return; + + //since we are the master view controller of a split view + //we know there is a parent UISplitViewController + NSArray *controllers = self.splitViewController.viewControllers; + + //Excerpt from the documentation: + //http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UISplitViewController_class/Reference/Reference.html + //The array in this property must contain exactly two view controllers. + //The view controllers are presented left-to-right in the split view interface + //when it is in a landscape orientation. Thus, the view controller at index 0 + //is displayed on the left side and the view controller at index 1 is displayed + //on the right side of the interface. + + //if there aren't at least two controllers somethin went wrong + if([controllers count] < 2) + return; + + //get the detail controller + UIViewController *detailViewController = [controllers objectAtIndex:1]; + + //now you can do whatever you want to change + //controls or text on detail view controller + //EXAMPLE: + //UIView *detailView = detailViewController.view; + //detailView.backgroundColor = (indexPath.row % 2 == 0) ? [UIColor grayColor] : [UIColor blackColor]; + + //if you want to change the detail view controller + //just create a new array containing the master and + //new detail controller and set the property "viewControllers" + //of the current split view controller + UIViewController *newDetailController = [[UIViewController alloc] init]; + UIView *newDetailView = [[UIView alloc] initWithFrame:detailViewController.view.frame]; + newDetailView.backgroundColor = [UIColor yellowColor]; + newDetailController.view = newDetailView; + + NSArray *newControllers = [NSArray arrayWithObjects:self, newDetailController, nil]; + self.splitViewController.viewControllers = newControllers; + + [newDetailController release]; + [newDetailView release]; } diff --git a/MasterDetail/MasterDetail.xcodeproj/project.pbxproj b/MasterDetail/MasterDetail.xcodeproj/project.pbxproj index d6cc12b..46cec7e 100755 --- a/MasterDetail/MasterDetail.xcodeproj/project.pbxproj +++ b/MasterDetail/MasterDetail.xcodeproj/project.pbxproj @@ -155,7 +155,14 @@ isa = PBXProject; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MasterDetail" */; compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; hasScannedForEncodings = 1; + knownRegions = ( + English, + Japanese, + French, + German, + ); mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; projectDirPath = ""; projectRoot = "";