0

我正在尝试实现阅读更多功能。单击按钮时,我想显示截断的文本。

我的问题是我得到 NSInvalidArgument 异常与此代码:

-(IBAction) ReadMore:(id)sender
{
NSLog(@"%d",[comm length]);
NSRange range = [comm rangeOfComposedCharacterSequencesForRange:(NSRange){71, [comm length]}];
truncString = [comm substringWithRange:range];
NSLog(@"Welcome=%@",truncString);
}

我在 log=291 和异常中获得通信长度:

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“索引 361 无效”

任何帮助,将不胜感激 !

4

2 回答 2

0

范围不得超过接收器的范围。请阅读文档链接

试试这个:

NSRange range = [comm rangeOfComposedCharacterSequencesForRange:(NSRange){71, [comm length]-71}];
于 2013-10-28T11:29:28.073 回答
0
    NSString *comm = @"audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set audio session category set";
        NSLog(@"%lu",(unsigned long)[comm length]);
        NSRange range = [comm rangeOfComposedCharacterSequencesForRange:(NSRange){71, [comm length]-71}];
        NSString  *truncString = [comm substringWithRange:range];
        NSLog(@"Welcome=%@",truncString);

Range should be within string length.
于 2013-10-28T11:34:26.880 回答