SplitView Pass from Master to Detail Issue

Discussion in 'iOS Programming' started by newtoiphonesdk, Jun 30, 2012.

  1. newtoiphonesdk macrumors 6502a

    Jul 30, 2010
    I am trying to convert my iPad app from using a Tab Bar Controller as its Root View to using a Split View Controller for it. My code in my AppDelegate.h is:
    @class RootViewiPad;
    @class WebViewController2;
    @interface AppDelegate : NSObject <UIApplicationDelegate, UISplitViewControllerDelegate> {
    UIWindow *window;
    UISplitViewController *splitViewController;
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
    The .m is:
    #import "AppDelegate.h"
    #import "WebViewController2.h"
    @implementation AppDelegate
    @synthesize window;
    @synthesize splitViewController;
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        self.window.rootViewController = self.splitViewController;
        [self.window makeKeyAndVisible];
    return YES;
    I use IB to set all this up, and I Added a SplitViewController in the MainWindow, and connected the AppDelegate Connection for SplitViewController to the SplitViewController I added. Under the Navigation Controller in the SplitViewController I set the root view to RootViewiPad (The TableView that parses a blog and shows the articles), and then set the other View Controller Class and NIB to WebViewController2 which is where I would like the articles to display once they are clicked on. When I run the app, it compiles, and I can see the WebViewController2 that I built in IB, and when I rotate, the left hand side is the TableView I created. However, I can't figure out how to get it to load the URL in the WebViewController2. Everything I have tried either does nothing, or merely pushes it on the Master Side of the controller.
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        WebViewController2 *detailViewController = 
        detailViewController.webView.scalesPageToFit = NO;
        RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
        [detailViewController.webView loadHTMLString:entry.articleImage baseURL:[NSURL URLWithString:nil]];  
    Any suggestions?
  2. MattInOz macrumors 68030


    Jan 19, 2006
    Try grabbing the ViewController already attached DetailView to your storyboard, instead of making a new instance.
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        WebViewController2 *detailViewController = (WebVeiwController2 *)
        [[self.splitViewController.viewControllers lastObject] topViewController];
        // something like this to then pass the data object for the selected row to the detail view.
        [detailViewController setDetailItem:[yourDataSource objectAtIndexPath:indexPath]];
    From there You'll need a method on that view controller that accepts the new data that drives the view and does whats needed to cause the view to redraw around the view. I haven't really used web views so not sure if that method already exists.

Share This Page