如何从barbuttonitem切换视图?

时间:2012-07-31 16:48:45

标签: ios uibarbuttonitem

我有一个叠加层,我在其中创建了一个包含完成按钮的工具栏。 完成按钮的选择器的名称是doneButtonPressed。

现在当我点击完成按钮时,如何获得新的笔尖视图?让我们假设我创建了一个名为TestViewController的笔尖。

-(void)doneButtonPressed {

//What goes here?

}

1 个答案:

答案 0 :(得分:0)

如果要从笔尖实例化UIViewController,可以使用以下代码行:

UIViewController *viewControllerName = [[UIViewController alloc] initWithNibName:(NSString *) bundle:(NSBundle *)];

然后,您可以使用以下方式模拟显示视图:

[self presentModalViewController:(UIViewController *) animated:(BOOL)];

现在,如果您正在使用故事板,那么您可以从故事板对象中实例化视图控制器。

不确定这是否是您要找的,但您可以将视图转换为“容器视图”。为此,您需要创建子视图,然后将其切换出来。当我想要一个菜单​​来控制不同的视图时,我这样做了。

[self.view insertSubview:(view you want to insert) atIndex:0];

然后当你想要把它关掉时:

[[[self.view subviews] objectAtIndex:0] removeFromSuperview];
[self.view insertSubview:(view you want to replace with) atIndex:0];

EDITED

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonPressed:)];

- (void)doneButtonPressed {

SkipQViewController *skipQ = [[SkipQViewController alloc] initWithNibName:@"Name" bundle:bundleName];
[self presentModalViewController:skipQ animated:YES];
}

如果不起作用,请尝试使用:SkipQViewController *skipQ = [[SkipQViewController alloc] init];来实例化视图控制器。

- 编辑 -

实例化视图控制器:SkipQViewController *skipQ = (SkipQViewController *)[[UIViewController alloc] initWithNibName:@"sqvc" bundle:nil];

相关问题