ios making a button change view when text field eq

2019-02-19 18:04发布

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条回答
爷的心禁止访问
2楼-- · 2019-02-19 18:17

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.

查看更多
登录 后发表回答