IOS制作按钮改变视图时,文本字段等于字符串 [英] ios making a button change view when text field equals string
问题描述
我提出这种密码跳过游戏中的级别。但我不知道是什么code我需要一个按钮改变视图控制器...
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...
任何想法?
超:有没有使密码不区分sensetive任何方法
Extra: Is there any method to make the password not case sensetive?
推荐答案
您有什么似乎罚款尽可能去。为了使比较不区分大小写的,你可以使用
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) {
// ...
}
要更改的ViewController ...这是一个基于故事板的设计?如果是这样,你可以写
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];
}
其中, SegueToLevel2CV
是你给了进入下一级别的SEGUE,当你构建了故事板中Interface Builder中输入的标识符。
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.
这篇关于IOS制作按钮改变视图时,文本字段等于字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!