简体   繁体   中英

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

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 added splitview controller to my xib file. how can i write programming part. any use ful links or souce codes please.

I am using view based class like as follows:
- (void)viewDidLoad
{
    [super viewDidLoad];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

where do i implement code? Thanks in advance.

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];

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM