problem with text length iPhone sdk
Hi dear friends i have 495 cells and a textField for inserting number and selecting the row according to the cell number .
i have problem with this code :
int MAX_LENGTH = 495;
(MAX_LENGTH >[myTextField.text length]{
myTextField.text = @"ERORR";
and this :
for(int i = 0; i <[myTextField.text intValue]; i++) {
[myScrollTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
when user insert a number greater than 495 my app crashes so , how can i mix them to work fine ! ?
i开发者_JAVA技巧 try to use if / else if / if if but neither worked ! thanks a lot ,
Your check is wrong. It is not the max length, if user enter "1000", the length is 4, and it will absolutely less than your MAX_LENGTH
Replace this:
int MAX_LENGTH = 495;
(MAX_LENGTH >[myTextField.text length]{
myTextField.text = @"ERORR";
with
int MAX_NUMBER = 495;
NSString *inputtedText = myTextField.text;
NSInteger inputtedNumber = [inputtedText intValue];
if (inputtedNumber > MAX_NUMBER) {
myTextField.text = @"ERROR";
}
精彩评论