ios making a button change view when text field equals string

两盒软妹~` 提交于 2019-12-01 08:14:19

问题


I am making this kind of password to skip levels in a game. But I dont know what code I need to make a button change View Controller...


- (IBAction)button:(id)sender {
    if ([txt.text isEqualToString:@"passwordToSkipLevel1"]) {
   // Code to change View Controller???
  }
}

I am not sure if I have done it correct to far, and I am not sure how I can make it change View Controller either...

Any ideas?

Extra: Is there any method to make the password not case sensetive?


回答1:


What you have seems fine as far as it goes. To make the comparison case-insensitive, you can use

if ([txt.txt localizedCaseInsensitiveCompare:@"passwordToSkipLevel1"] == NSOrderedSame) {
    // ...
}

To change ViewController... is this a storyboard-based design? If so, you could write

if ([txt.txt localizedCaseInsensitiveCompare:@"passwordToSkipLevel1"] == NSOrderedSame) {
    [self performSegueWithIdentifier:@"SegueToLevel2VC" sender:self];
}

where SegueToLevel2CV is the identifier you've given the segue that goes to the next level, typed in to Interface Builder when you constructed the storyboard.



来源:https://stackoverflow.com/questions/13791217/ios-making-a-button-change-view-when-text-field-equals-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!