n0n4m3
n0n4m3

Reputation: 41

uisplitviewcontroller: passing selected row from master to detail

it's now a couple of days I've been struggling with UISplitViewControllers, here's my problem: I have a master view which is declared as follows

#import <UIKit/UIKit.h>
#import "DetailViewController.h"

@class DetailViewController;
@interface MasterViewController : UITableViewController {
    NSMutableArray *title, *subTitle;
    unsigned int quantity;
}

@property (strong, nonatomic) DetailViewController *detailViewController;
@end

In the master's .m file everything works correctly (I'm able to populate the table from a sqlite db and show the contents in rows). When it comes to select one row and populate the detailed view on the right side nothing happens. Here is the row selection:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyObject itemFromDB;
    /* 

    ... DB stuff here ...

    */

    self.detailViewController.detailItem = itemFromDB;  
}

Here's now the DetailViewController implementation:

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
@property (strong, nonatomic) MyObject *detailItem;
@property (weak, nonatomic) IBOutlet UILabel *name, *phone;
@end

And the detail's .m:

#import "DetailViewController.h"
@interface DetailViewController ()
- (void)configureView;
@end

@implementation DetailViewController

- (void)setDetailItem:(MyObject *)newItem
{
    if (_detailItem != newItem) {
        _detailItem = newItem;
        [self configureView];
    }
}

- (void)configureView
{
    if (self.detailItem) {
        self.name.text = [self.detailItem name];
        self.phone.text = [self.detailItem phone];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self configureView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
} 

In simple words: the detail isn't noticing any changes after the selection of a row. Any help?

Upvotes: 0

Views: 1217

Answers (1)

rdelmar
rdelmar

Reputation: 104082

You never defined self.detailViewController. You should do this:

self.detailViewController = self.splitViewController.viewControllers[1];

Upvotes: 3

Related Questions