how can i add splitview to my viewbased app in ipad coding

前端 未结 3 1827
梦如初夏
梦如初夏 2021-01-07 09:20

I am Started my iPad app using View-Based application. in first two views i added table views. Now as the third view i want add splitView to the view, for this purpose i add

相关标签:
3条回答
  • 2021-01-07 09:48

    The SplitViewController has to be the RootViewController. From Apple Docs:

    "A split view controller must always be the root of any interface you create. In other words, you must always install the view from aUISplitViewController object as the root view of your application’s window. The panes of your split-view interface may then contain navigation controllers, tab bar controllers, or any other type of view controller you need to implement your interface."

    So you cannot do what you want without writing your own container views (in iOS5) instead of using Apple' SplitViewController.

    0 讨论(0)
  • 2021-01-07 09:50

    When you want to switch to your splitview controller you need to alloc/init it then you need to set your windows root view controller to the splitview controller.

    For example in my app, I have a main home view, and when the user taps a button I switch to a splitview. To swtich to the splitview controller I use the following code.

    Get a reference to your app delegate

    MainAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    

    Alloc and initialise your splitview controller, so for my example I have a section list controller on the left, and a section details controller on the right:

    SectionListViewController *sectionListVC = [[SectionListViewController alloc] init];
    SectionViewController *sectionVC = [[SectionViewController alloc] init];
    
    UISplitViewController *splitVC = [[UISplitViewController alloc] init];
    splitVC.viewControllers = [NSArray arrayWithObjects:sectionListVC, sectionVC, nil];
    
    appDelegate.window.rootViewController = splitVC;
    
    [sectionListVC release];
    [sectionVC release];
    [splitVC release];
    
    0 讨论(0)
  • 2021-01-07 09:57

    As i know about split view controller you have to create new split View based app or you have to implement through programmatically. for this you need to create one master view controller which hold splitview and one table view controller without nib file and contain table view controller add one more view controller which display details

    write the below code in master controller
    implementing code like: in .h page

     UISplitViewController *splitViewController;
    @property (nonatomic, retain) IBOutlet LeftViewController *left;
    @property (nonatomic, retain) IBOutlet DetailViewController *right;
    

    in .m page

       // Do any additional setup after loading the view from its nib.
    left = [[LeftViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *leftNav = [[UINavigationController alloc] initWithRootViewController:left];
    right = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
    UINavigationController *rightNav = [[UINavigationController alloc] initWithRootViewController:right];
    left.detail = right;
    
    splitViewController = [[UISplitViewController alloc] init];    
    splitViewController.viewControllers = [NSArray arrayWithObjects:leftNav,rightNav, nil];
    splitViewController.delegate = right;
    self.view = splitViewController.view;
    
    [left release];
    [right release];
    

    all the start up method written in viewDidLoad not in viewWillAppear

    0 讨论(0)
提交回复
热议问题