gpt4 book ai didi

objective-c - Xcode 4.5 ios6 按钮在 objective-c 中打开新 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:00 26 4
gpt4 key购买 nike

我知道如何通过拖放在 Storyboard中获得一个按钮来打开一个新的 ViewController(新类)。但我需要一段代码,我可以在 .m 文件中编写代码,以便在单击我的按钮时打开一个新 View 。

在我的 FirstViewController.m 中我得到了:

- (IBAction)button1:(id)sender {

}

我需要什么代码来获取打开 SecondViewController 的按钮?

最佳答案

[self performSegueWithIdentifier: @"TheSequeName" sender: self];

@"TheSequeName"是在您按住 ctrl 键拖动按钮以在 Storyboard上打开新的 View Controller 时定义的

如果你不使用 segue,有很多变体可以打开一个新的 View Controller 。最基本的是使用单独的 NIB(没有 Storyboard)

SecondViewController *view = [[SecondViewController allow] initWithNibName:@"NibName" bundle:nil];

如果你在 Storyboard 上声明你的 View Controller ,你可以使用

SecondViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:@"viewStoryboardId"]; 

然后您使用导航 Controller 显示您的 SecondViewController

[self.navigationController pushViewController:view animated:YES];

或者作为模态视图

[self presentModalViewController:view animated:YES];

关于objective-c - Xcode 4.5 ios6 按钮在 objective-c 中打开新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13217859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com