【发布时间】:2012-05-17 23:21:38
【问题描述】:
我在文本字段中有一些文本,它们以 6 个字符开头,我自己的输入也是 6 个字符长,我使用此代码将它们作为比较的一部分:
unichar aChar1 = [mainTextController.text characterAtIndex:6];
unichar aChar2 = [mainTextController.text characterAtIndex:7];
unichar aChar3 = [mainTextController.text characterAtIndex:8];
unichar aChar4 = [mainTextController.text characterAtIndex:9];
unichar aChar5 = [mainTextController.text characterAtIndex:10];
unichar aChar6 = [mainTextController.text characterAtIndex:11];
现在,当我这样做时,它会暂停我的模拟器,但是当我在 0、1、2、3、4、5 转 6、7、8、9、10、11 时,它确实可以工作。怎么会?
(* 由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'-[__NSCFString characterAtIndex:]: Range or index out of bounds') 谁能给我解释一下
【问题讨论】:
标签: iphone objective-c xcode