问题
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