简体   繁体   English

UIButton不会打开新的视图控制器

[英]UIButton won't open new view Controller

I am having trouble getting a new view controller to show on the screen when the button is pressed. 按下按钮时,我无法在屏幕上显示新的视图控制器。 I created a subclass of UIViewController named StartUpVC . 我创建了一个名为StartUpVCUIViewController的子类。 I added it to the app delegate.m and created an instance of StartupVC *startUpVC = [StartUpVC new] and then set self.window.rootViewController = startUpVC; 我将它添加到app delegate.m并创建了一个StartupVC *startUpVC = [StartUpVC new]实例StartupVC *startUpVC = [StartUpVC new]然后设置self.window.rootViewController = startUpVC; . So now in the StartUpVC class, I created a button so a user can log in with a UIImageView in the background. 所以现在在StartUpVC类中,我创建了一个按钮,以便用户可以在后台使用UIImageView登录。 Now when the button is pressed, it doesn't open up the view controller for the log in screen and does nothing. 现在,当按下按钮时,它不会打开登录屏幕的视图控制器,也不执行任何操作。 So my question is how do i get it to open that view controller? 所以我的问题是如何让它打开那个视图控制器? Or should it simply be a UIView that opens when the button is pressed? 或者它应该只是按下按钮时打开的UIView

This is in the StartUpVC.m 这是在StartUpVC.m中

- (void)viewDidLoad
{
    [super viewDidLoad];
 ...Code Irrelevant to the question here...

//Create Log In Button
    UIButton *logInButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    logInButton.frame = CGRectMake(20, 480, 280, 40);
    logInButton.layer.cornerRadius = 4.0f;
    logInButton.layer.opacity = .6;
    logInButton.backgroundColor = [UIColor lightGrayColor];
    [logInButton setTitle:@"Log In" forState:UIControlStateNormal];
    [logInButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [logInButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    [logInButton addTarget:self action:@selector(sendToLogInScreen:) forControlEvents:UIControlEventTouchUpInside];


    [self.view addSubview:logInButton];

}

-(void)sendToLogInScreen:(id)sender {

    LogInVC *logIn = [LogInVC new];

    [self presentViewController:logIn animated:YES completion:nil];

}

First thing you need to know is whether the method sendToLogInScreen is getting called at all. 首先需要知道的是sendToLogInScreen方法是否sendToLogInScreen被调用。 Place a breakpoint anywhere in the function to check. 在函数中的任何位置放置断点以进行检查。

Once you know whether the function is getting called at the proper time or not, this problem will either be about: 一旦你知道函数是否在适当的时间被调用,这个问题将是:

  • sendToLogInScreen is not getting called sendToLogInScreen没有被调用
    • Something is wrong with the button 按钮有问题
      • it's nil 它没有
      • the gesture isn't setup properly 手势设置不正确
    • UserInteraction is disabled for StartupVC 's view property StartupVCview属性禁用UserInteraction
  • sendToLogInScreen is getting called sendToLogInScreen被调用
    • logIn is nil logIn是零
    • presentViewController is failing for some reason presentViewController由于某种原因失败了

Hope that helps you figure out what might be causing the issue. 希望能帮助您找出可能导致问题的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 视图控制器不会立即关闭并呈现新的视图控制器 - View Controller won't dismiss and present new view controller immediately 邮件撰写视图控制器无法从UIAlertController打开 - Mail Compose View Controller Won't Open From UIAlertController 登录窗口不会在下一个视图控制器中打开 - Login Window won't open in next view controller Swift UIButton,Mapbox,以编程方式打开新视图 - UIButton, Mapbox, Open new View programmatically 视图控制器不会初始化 - View controller won't initialise 添加到视图的子视图的UIButton无法响应 - UIButton Added to a View's Subview Won't Respond UIButton在视图控制器上不起作用 - UIButton not working on view controller 如何在UITableViewCell中点击UIButton并过渡到新的视图控制器,并传递信息? - How to tap on a UIButton in a UITableViewCell and transition to a new view controller, passing it information? 如何在点击UIButton后在UIPageViewController中添加新的视图控制器? - How to add a new view controller in UIPageViewController after UIButton was tapped? 无法将UIButton事件正确发送到其他视图控制器 - Can't send a UIButton event to other view controller correctly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM