在基于拆分的应用程序中手动更改视图

时间:2012-07-19 15:57:47

标签: objective-c uisplitviewcontroller

我试图在用户点击“提交”按钮后让我的应用切换视图。

这是我到目前为止所做的:

viewA.h

@property (nonatomic, retain) RootViewController *root;

viewA.m

-(void)switchToLogView{

NSLog(@"switch to log view");

UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
LogDetailViewController *newDetailViewController = [[LogDetailViewController alloc] initWithNibName:@"LogDetailViewController" bundle:nil];
detailViewController = newDetailViewController;

// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
root.splitViewController.viewControllers = viewControllers;

// Dismiss the popover if it's present.
if (root.popoverController != nil) {
    [root.popoverController 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 (root.rootPopoverButtonItem != nil) {
    [detailViewController showRootPopoverButtonItem:self.root.rootPopoverButtonItem];
}

[detailViewController release];

}

splitViewControllerpopoverControllerrootPopoverButtonItem都在我的RootViewController课程中声明(我从苹果示例代码开始)。

代码构建正常,但是当我调用方法时,没有任何反应。

1 个答案:

答案 0 :(得分:0)

我最近也必须学习如何做到这一点。我想在我的屏幕上显示一个“约”按钮,当用户点击按钮时,该按钮会翻转到另一个视图,然后当他们点击“完成”按钮时,将其翻转回原始视图。

我认为你过于复杂了。这是我要提出的关于视图的代码。

AboutViewController *aboutViewController = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];

aboutViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:aboutViewController animated:YES]; //Show it!

显然,不要忘记在标题中导入它:#import <AboutViewController.h>

我带回原始视图的代码(也就是隐藏关于视图)是:[self.parentViewController dismissModalViewControllerAnimated:YES];