Reputation: 1385
I am creating an iPad version of Master Detail Application using XCode 4.5 with ARC. I have my iPadMaster.h/.m(as my master) and iPadDetailViewController.h/m(as my detail) set up.
I am trying to load different view controllers from iPadDetailViewController when users click/select the rows on iPadMaster.
On iPadDetailController.h, i set this:
@property int itemNumber;
On iPadMaster.h, i called it as:
@class iPadDetailViewController;
and proceeded with this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController * DVC = [[DetailViewController alloc]init];
DVC.itemNumber = indexPath.row;
}
On iPadDetailViewController, i set this:
- (void)configureView
{
switch (_itemNumber) {
case 1:
{
iPadLogin *next = [[iPadLogin alloc] init];
NSMutableArray *mut = [[NSMutableArray alloc]init];
mut = [self.splitViewController.viewControllers mutableCopy];
[mut replaceObjectAtIndex:1 withObject:next];
self.splitViewController.viewControllers = mut;
break;
}
default:{
self.view.backgroundColor = [UIColor whiteColor];
}
break;
}
}
//then i called it on:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
When i clicked the second row in the master table, item_number should be 1 and load the 'iPadLogin' but nothing happens... Any pointers is much appreciated...
Thanx in advance...
Upvotes: 0
Views: 190
Reputation: 104082
As I said in my comment, I think you should change the detail controller from the master controller. It is in the master that you're making the decision on what detail controller to go to (by picking a row in the table), so it should be the responsibility of the master controller to make the change. The code below should do that (note, however, if you're using a storyboard for your controllers, then you should be using [self.storyboard instantiateViewControllerWithIdentifier:@"whatever"] to get your next controller rather than alloc init).
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
case 1:
{
iPadLogin *next = [[iPadLogin alloc] init];
NSMutableArray *mut = [[NSMutableArray alloc]init];
mut = [self.splitViewController.viewControllers mutableCopy];
[mut replaceObjectAtIndex:1 withObject:next];
self.splitViewController.viewControllers = mut;
break;
}
case 2:
{
AnotherVC *another = [[AnotherVC alloc] init];
NSMutableArray *mut = [[NSMutableArray alloc]init];
mut = [self.splitViewController.viewControllers mutableCopy];
[mut replaceObjectAtIndex:1 withObject:another];
self.splitViewController.viewControllers = mut;
break;
}
default:{
UIViewController *detail = self.splitViewController.viewControllers[1];
detail.view.backgroundColor = [UIColor whiteColor];
}
break;
}
}
Upvotes: 1