Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIButton,UIAlertView设置操作_Ios_Uibutton_Uialertview - Fatal编程技术网

Ios UIButton,UIAlertView设置操作

Ios UIButton,UIAlertView设置操作,ios,uibutton,uialertview,Ios,Uibutton,Uialertview,我有一个简单的问题,请帮助我,因为我真的卡住了。我需要的是切换到另一个ViewController后,登录按钮被按下,如果登录和密码不是空的 我有一个简单的登录界面与用户名,密码和登录按钮。当密码或登录名为空时,将显示UIAlertView,代码如下: .m文件 - (IBAction)login:(id)sender { if (userName.text.length == 0 || password.text.length == 0){ UIAlertView *a

我有一个简单的问题,请帮助我,因为我真的卡住了。我需要的是切换到另一个ViewController后,登录按钮被按下,如果登录和密码不是空的

我有一个简单的登录界面与用户名,密码和登录按钮。当密码或登录名为空时,将显示UIAlertView,代码如下:

.m文件

- (IBAction)login:(id)sender {
    if (userName.text.length == 0 || password.text.length == 0){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Complete All Fields" message:@"You must complete all fields to login!" delegate:self cancelButtonTitle:@"Good" otherButtonTitles:nil, nil];
        [alert show]; 
    }
}

如何添加按钮切换到其他UIController的操作?这一个一直在崩溃
[自我呈现ModalViewController:anotherUIViewController动画是]这里还有一个通知-“应用程序试图在目标上显示一个无模式视图控制器。”

根据您使用的是XIB还是故事板,只保留下面解释的一行

- (IBAction)login:(id)sender {
    if (userName.text.length == 0 || password.text.length == 0){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Complete All Fields" message:@"You must complete all fields to login!" delegate:self cancelButtonTitle:@"Good" otherButtonTitles:nil, nil];
        [alert show];
    }else{
        //if you are using xibs use this line
        UIViewController *anotherUIViewController = [[UIViewController alloc] initWithNibName:@"anotherUIViewController" bundle:[NSBundle mainBundle]];
        //
        //if you are using storyboards use this line
        UIViewController *anotherUIViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"someIdentifierForThisController"];
        //
        //then simply present the view controller
        [self presentViewController:anotherUIViewController animated:YES completion:nil];
    }
}

它崩溃是因为应用程序试图呈现一个无模式视图控制器。什么是另一个uiviewcontroller以及如何显示它?另一个uiviewcontroller是我想在按下登录按钮后打开的uiviewcontroller。因此,如果登录和密码不是空的,我需要在按下登录按钮后切换到另一个ViewController。你的问题非常广泛,如前所述。需要帮助将按钮按下与方法关联吗?(如果是这样的话,我建议你花更多的时间学习你选择的教程)你的问题是让函数不崩溃吗?崩溃是——正如错误告诉您的那样——因为您试图推送一个模态视图控件值“nil”——也就是说,无论您在哪里推送新的视图控制器,您都没有给它一个有效的VC。如果不让我们看到背后的代码,我们甚至无法开始帮助您。