[英]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
. 我创建了一个名为StartUpVC
的UIViewController
的子类。 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
没有被调用
StartupVC
's view
property 对StartupVC
的view
属性禁用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.