[英]NSRange not matching with NSNotFound
I have the following method: 我有以下方法:
- (IBAction)digitPressed:(UIButton *)sender {
NSLog(@"%@", sender.currentTitle);
if (self.userTypingNumber) {
if (![sender.currentTitle isEqualToString:@"."])
self.display.text = [self.display.text stringByAppendingString:sender.currentTitle];
else {
NSRange range = [sender.currentTitle rangeOfString:@"."];
if (range.location == NSNotFound) {
self.display.text = [self.display.text stringByAppendingString:sender.currentTitle];
}
}
} else {
self.display.text = sender.currentTitle;
self.userTypingNumber = YES;
}
}
My problem is that my program never enters de NSNotFound if. 我的问题是,如果我的程序从不输入de NSNotFound。 I'm making a calculator and it should accept floating point numbers, but whenever I press the .
我正在制作一个计算器,它应该接受浮点数,但是每当我按下时。 it just passes right over the if.
它只是通过if。 Any idea what could be wrong?
知道有什么问题吗?
Looking at your logic, sender.currentTitle
is always going to be @"."
查看您的逻辑,
sender.currentTitle
始终为@"."
in your else statement, and so your range is always going to have a location of 0. 在您的else语句中,因此您的范围始终将位置为0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.