【问题标题】:Show another view with IBAction - XIB and Storyboard使用 IBAction 显示另一个视图 - XIB 和 Storyboard
【发布时间】:2011-12-25 08:37:58
【问题描述】:

我正在成功使用 Storyboard。一个屏幕不是“空的”,它有一个 NotifierViewController 类。

这个类有一个 .h,.m 和 XIB 文件。该应用程序运行良好。

现在我需要在 XIB 文件中添加一个按钮来将此视图链接回我的情节提要。现在,我必须停止并重新启动应用才能看到主视图。

所以在 IB 中,我在 .h 和 .m 文件中创建了一个 UIButton 和一个 IBAction。但是我的操作代码没有运行。我只是黑屏。

我的 Storyboard 中的“初始视图控制器”视图具有类 ViewController(仅 .h 和 .m 文件)

怎么了?

#import "NotifierViewController.h"
#import "ViewController.h"

- (IBAction)home:(id)sender {
    NSLog(@"Button was tapped");
    // init & alloc - Replace with your custom view controllers initialization method (if applicabale)
    ViewController *viewController = [[ViewController alloc] init];
    [viewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentViewController:viewController animated:YES completion:NULL];
    [ViewController release];
}

【问题讨论】:

    标签: cocoa-touch xib storyboard


    【解决方案1】:

    您不应该重新初始化并代表您的主要“根”视图。如果您要以模态方式呈现此 NotifierViewController,则可以将其关闭:

    - (IBAction)home:(id)sender {
        [self dismissModalViewControllerAnimated:Yes];
    }
    

    如果 NotifierViewController 没有以模态方式呈现,请告诉我怎么做,我将编辑我的答案。

    【讨论】:

    【解决方案2】:
    - (IBAction)home:(id)sender 
    {
    
        UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController* initialHelpView = [storyboard instantiateInitialViewController];
    
        initialHelpView.modalPresentationStyle = UIModalPresentationFormSheet;
        [self presentModalViewController:initialHelpView animated:YES];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 2018-03-16
      • 2023-03-06
      • 2012-06-18
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多