【问题标题】:Objective-C: How to make a button take you to another class/storyboardObjective-C:如何让一个按钮带你到另一个班级/故事板
【发布时间】:2014-10-19 19:51:53
【问题描述】:

我想在右侧的故事板中显示底部按钮,以便在用户点击按钮时将用户带到左侧的 signupstoryboard.storyboard/signupController。怎么可能?

{ - (IBAction)signupbutton:(id)sender; SignupController *signUpView = [self.storyboard instantiateViewControllerWithIdentifier:@"signup"]; [self presentViewController:signUpView animated:YES completion:nil]; }

【问题讨论】:

  • 不要在问题中发布代码截图。只需复制并粘贴代码即可。我几乎看不懂那个截图中的代码。
  • @Larme 这对我有什么帮助?这个家伙并没有选择一个特定的按钮来把他带到一个故事板,他只是命名一个故事板来过渡到另一个故事板。我需要一些帮助,我是 Objective-c 的新手
  • 你构建的方法全错了。
  • 用我的版本替换你从{ - (IBAction)开始的整个方法

标签: objective-c storyboard


【解决方案1】:

你必须通过代码来完成。

- (IBAction)buttonTapped
{
    NSString *storyboardName = @"signupstoryboard";
    UIViewController *nextViewController = [[UIStoryboard storyboardWithName:storyboardName bundle:nil] instantiateInitialViewController];
    // if you are using a navigation controller to push it:
    [self.navigationController pushViewController:nextViewController animated:YES];
    // otherwise if you are presenting it modally:
    [self presentViewController:nextViewController animated:YES completion:nil]    
}

【讨论】:

  • 是的,但是当我专门单击名为 signupButton 的底部按钮时,我希望它转到下一个视图控制器。基本上当我点击它时,我希望它带我进入注册页面,这是一个单独的控制器/故事板
  • 是的...将该按钮连接到上述方法(尽管显然将情节提要名称与实际名称切换)。
  • 这是我的代码,它给了我一个错误“预期表达式”{ - (IBAction)signupbutton:(id)sender; SignupController *signUpView = [self.storyboard instantiateViewControllerWithIdentifier:@"signup"]; [self presentViewController:signUpView 动画:YES 完成:nil]; }
  • 视图控制器是否真的获得了 Storyboard ID“注册”?
  • 你的方法完全错误。看看我的方法,然后看看你的,看看结构上的差异,
【解决方案2】:

在您的 .m 中(在顶部)

#import "signupController.h"

在您的按钮操作方法中(不要忘记将您的 signupController 的情节提要 ID 设置为注册

- (IBAction)signupbutton:(id)sender
{
    SignupController *signUpView = [self.storyboard instantiateViewControllerWithIdentifier:@"signup"]; [self presentViewController:signUpView animated:YES completion:nil];
}

就是这样

【讨论】:

  • 这很有意义,但是当我这样做时,我的应用程序给了我 SIGABRT 并且应用程序崩溃了......
  • 错误不在您的代码中。在这部分: - (IBAction)signupbutton:(id)sender;它说“预期的表达”
  • @RobertVanGilder 在 signupstoryboard 的 Connections Inspector 中检查您的按钮连接。它应该只有 1 个 touchUpInside 事件连接到您signupbutton 方法
  • 它确实有一个touchupinside。但问题是,当点击 loginstoryboard 中的注册按钮时,我想将具有“注册”按钮的 LoginStoryboard 与 SignupStoryboard 连接起来......
  • 截取错误并在您的问题中更新。这将使我更好地了解您遇到的问题
猜你喜欢
  • 2018-07-24
  • 1970-01-01
  • 2016-05-04
  • 1970-01-01
  • 1970-01-01
  • 2017-02-22
  • 2013-09-17
  • 1970-01-01
  • 2014-11-13
相关资源
最近更新 更多