在弹出框中添加一个按钮

时间:2012-09-06 22:29:47

标签: ios uipopovercontroller popover

在Xcode中是否可以在弹出窗口中添加一个按钮,将用户带到新视图?

1 个答案:

答案 0 :(得分:4)

[myPopOver.contentViewController.view addSubview:myButton];
[myButton addTarget:self action:@selector(goToNextView) forControlEvents:UIControlEventTouchUpInside];

- (void)goToNextView
{
 //if you are using xibs use this line
    UIViewController *controller = [[UIViewController alloc] initWithNibName:@"myXib" bundle:[NSBundle mainBundle]];
//if you are using storyboards use this line
    UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"myViewControllersID"];

//to present the controller modally use this
    [self presentViewController:controller animated:YES completion:nil];
//or if you are pushing to this controller using a navigation controller use this
    [self.navigationController pushViewController:controller animated:YES];
}