[英]UIButton,UIAlertView setting action
我有一個簡單的問題,請幫助我,因為我真的卡住了。 我需要的是,如果登錄和密碼不為空,則在按下登錄按鈕后切換到另一個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? 這一個一直在粉碎[self presentModalViewController: anotherUIViewController animated YES];
這里也是通知 - “應用程序試圖在目標上呈現一個零模態視圖控制器。”
根據您使用的是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];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.