Search code examples
iosxcodeipaduisplitviewcontroller

SplitViewController does not update detailView getting desperate


I cant figure out what the problem is, i used 2 tutorials and the example Apple gives you but still it will not update. I am trying to fix this for 4 days now Some info: I am using storyboard for this project

Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
return YES;
}

MasterViewController.m

Made an property to the controller (nieuwViewController)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SearchResult *searchResult = [searchResults objectAtIndex:indexPath.row];
NSLog(@"%@",searchResult);

self.nieuwViewController.searchResult =searchResult;
}

NieuwViewController.m

- (void)setSearchResult:(SearchResult *)newSearchResult
{
if (_searchResult != newSearchResult) {
    _searchResult = newSearchResult;

    // Update the view.
    [self updateUI];
}

}


- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"DETAIL VIEWDIDLOAD");
NSLog(@"%@",self.searchResult);
[self updateUI];

}

In the updateUI i set all the labels etc, but if i log that too its called one time (when the application starts)


Solution

  • viewDidLoad get's only called once during initialization of the NIB or storyboard. Use viewWillAppear to update the ui. But bear in mind, that in a SplitViewController the detail view won't update automatically; trigger the update from didSelectRowAtIndexPath.