使用右侧导航栏按钮从 nib 文件推送视图

发布于 2024-12-06 09:36:37 字数 365 浏览 6 评论 0原文

正如标题中所述,我想使用导航栏上的按钮从已知的 NIB 推送视图。我正在开发 UINavigationController 应用程序。

我已经在 IB 中添加了右侧按钮,并将其链接到 RootViewController 中的方法,

我到处搜索,但找不到执行此方法的方法...

-(IBAction)addItems:(id)sender 
{
    ?
}

我也尝试过 此解决方案,但它也不起作用......

As described in the title, i would like to push a view, from a known NIB, using a button on the navigation bar. I'm working on a UINavigationController app.

I already added the right button in IB and i linked it to the method that is in the RootViewController

I have searched everywhere but I couldn't find a way to do this method...

-(IBAction)addItems:(id)sender 
{
    ?
}

I also tried this solution, but it isn't working either...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠北森屋 2024-12-13 09:36:37

例如:

-(IBAction)addItems:(id)sender 
{
    CustomController *controller = [[CustomController alloc] initWithNibName:@"CustomController" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

其中

  1. CustomController 是您的自定义控制器类的名称。
  2. @"CustomController" xib 文件的名称

For example:

-(IBAction)addItems:(id)sender 
{
    CustomController *controller = [[CustomController alloc] initWithNibName:@"CustomController" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

Where

  1. CustomController name of your custom controller class.
  2. @"CustomController" name of your xib file
过潦 2024-12-13 09:36:37

如果你只需要 nib 文件中的视图,那么试试这个..

NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"QPickOneView"
                                                  owner:self
                                                options:nil];

UIView* myView = [ nibViews objectAtIndex: 0];

self.view = myView;

如果你想推送 ViewController..那么请使用 Nekto 的答案。

If you just need the view from nib file, then try this..

NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"QPickOneView"
                                                  owner:self
                                                options:nil];

UIView* myView = [ nibViews objectAtIndex: 0];

self.view = myView;

If you want to push a ViewController..Then go with the Nekto's Answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文