I have developed an iPhone application and now I would like to implement a UISplitViewController which will launch on startup if the application is being run on an iPad.
To get the split view to start working I have copied most of the code from the MultipleDetailViews project from Apple.
I have a few questions, if I may:
- 1) Is it possible to re-use the classes I created for the iPhone application to display as the "detail" view of the split view controller?
- 2) I have the split view controller loading programmatically, but the little button to present the popover doesn't appear. I have tried many ways and debugged, and the code that runs to present the popover button is running, but nothing happens. Any ideas?
- 3) I have created a .xib that is correctly wired up with a splitviewcontroller. Is it possible to get this xib to load at startup instead of programmatically creating the splitviewcontroller?
On launching - this is the code that I am currently using:
// manually create a split view controller
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// launch the ipad view
RootViewControllerPad *firstVC = [[[RootViewControllerPad alloc]
initWithNibName:nil bundle:nil] autorelease];
IndicatorsPad* secondVC = [[[IndicatorsPad alloc]
initWithNibName:@"IndicatorsPad" bundle:nil] autorelease];
splitViewCtrl = [[UISplitViewController alloc] init];
splitViewCtrl.viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];
self.window.rootViewController = self.splitViewCtrl;
[window addSubview:splitViewCtrl.view];
}
The split view containers shows up, but like I say, it's not working properly. It should automatically present a button for the popover when the orientation changes to portrait, and it's not doing this.
When I select one of the items on the left menu, it doesn't bring up the required xib in the detail view even though the code is (probably) correct:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
Create and configure a new detail view controller appropriate for the selection.
*/
NSUInteger row = indexPath.row;
NSLog(@"Row %i selected",row);
UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
if (row == 5) {
IndicatorsPad *newDetailViewController = [[IndicatorsPad alloc] initWithNibName:@"IndicatorsPad" bundle:nil];
detailViewController = newDetailViewController;
}
if (row == 6) {
SensPad *newDetailViewController = [[SensPad alloc] initWithNibName:@"SensPad" bundle:nil];
detailViewController = newDetailViewController;
}
// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
[viewControllers release];
// Dismiss the popover if it's present.
if (popoverController != nil) {
[popoverControl开发者_JAVA百科ler dismissPopoverAnimated:YES];
}
// Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
if (rootPopoverButtonItem != nil) {
[detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
}
[detailViewController release];
}
I've spent a couple of days on this problems and really would appreciate the guidance. I have read several of the questions and answers in this forum and have reached the point where I feel that I need to ask these specific questions.
Thanks a lot.
精彩评论