我有這樣的代碼IOS:錯誤的home目錄
NSString *nextSequentialFile =
[filePath stringByReplacingOccurrencesOfString:photoNumber
withString:[NSString stringWithFormat:@"%d", (index + 1)]
options:NSBackwardsSearch
range:[filePath rangeOfString:photoNumber options:NSBackwardsSearch]];
但我有這個錯誤,我不明白怎麼一回事,因爲它發生。
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString replaceOccurrencesOfString:withString:options:range:]: Range or index out of bounds'
範圍:NSRangeFromString(filePath)]; //範圍或索引超出範圍' – CrazyDev
嘗試使用'NSMakeRange(0,filePath.length)'而不是'NSRangeFromString'。查看修改。 – chown