由于未捕获的异常 NSInvalidArgumentException 而终止应用程序,原因:索引无效
Posted
技术标签:
【中文标题】由于未捕获的异常 NSInvalidArgumentException 而终止应用程序,原因:索引无效【英文标题】:Terminating app due to uncaught exception NSInvalidArgumentException , reason: The index is invalid 【发布时间】:2013-11-14 11:02:40 【问题描述】:我是 ios 开发新手。当我运行我的应用程序时,出现以下错误。谁能帮帮我..
我在TableViewCell
中放置了一个UITextView
。我已将 'one\n' 设置为 UITextView
的文本。
我的代码:
- (id)initWithFrame:(CGRect)frame withIndexPath:(NSArray *)indexPath
self = [super initWithFrame:frame];
if (self)
mIndexPath = indexPath;
mRange = NSMakeRange(0,4);
self.delegate = self;
self.attributedText = @"one\n";
self.scrollEnabled = NO;
return self;
- (void)textViewDidBeginEditing:(TextView *)textView
[self updateRangeForSelection];
- (void)updateRangeForSelection
NSRange selectedRange = self.selectedRange;
NSLog(@"%d",selectedRange.location);
当我点击UITextView
时,我选择了Range
作为(3,0)。在我记录选定的范围后,我自己得到了以下异常。
例外:
2013-11-14 16:16:24.690 ZohoWriter[484:60b] ARRAY : (
0 CoreFoundation 0x2d488e9b <redacted> + 154
1 libobjc.A.dylib 0x37c3d6c7 objc_exception_throw + 38
2 CoreFoundation 0x2d488dc5 <redacted> + 0
3 Foundation 0x2de6911d <redacted> + 88
4 UIKit 0x2fdaee89 <redacted> + 328
5 UIFoundation 0x35038cd9 <redacted> + 36
6 UIKit 0x2fdaeceb <redacted> + 218
7 UIKit 0x2fdaeb79 <redacted> + 1128
8 UIFoundation 0x3501dde3 <redacted> + 46
9 UIKit 0x2fdae67b <redacted> + 222
10 UIKit 0x2fdae533 <redacted> + 54
11 UIKit 0x2fdae4d9 <redacted> + 132
12 UIKit 0x2fdac5f3 <redacted> + 2146
13 UIKit 0x2fd93739 <redacted> + 196
14 UIKit 0x2fc3e18b <redacted> + 1138
15 UIKit 0x2ffc9d4f <redacted> + 46
16 UIKit 0x2fc055cf <redacted> + 218
17 UIKit 0x2fc03d33 <redacted> + 298
18 UIKit 0x2fc3c9fd <redacted> + 772
19 UIKit 0x2fc3c3ab <redacted> + 666
20 UIKit 0x2fc11d79 <redacted> + 196
21 UIKit 0x2fc10569 <redacted> + 7116
22 CoreFoundation 0x2d453f1f <redacted> + 14
23 CoreFoundation 0x2d4533e7 <redacted> + 206
24 CoreFoundation 0x2d451bd7 <redacted> + 630
25 CoreFoundation 0x2d3bc471 CFRunLoopRunSpecific + 524
26 CoreFoundation 0x2d3bc253 CFRunLoopRunInMode + 106
27 GraphicsServices 0x320d02eb GSEventRunModal + 138
28 UIKit 0x2fc71845 UIApplicationMain + 1136
29 ZohoWriter 0x000bea1d main + 116
30 libdyld.dylib 0x38136ab7 <redacted> + 2
)
2013-11-14 16:16:24.695 ZohoWriter[484:60b] Exception : The index 4 is invalid
2013-11-14 16:16:24.696 ZohoWriter[484:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The index 4 is invalid'
terminating with uncaught exception of type NSException
Program received signal: “SIGABRT”.
我在这里做错了什么?
【问题讨论】:
展示代码怎么样,而不是描述它。 @Abizern : 你现在能检查一下吗? 【参考方案1】:提供的代码不是崩溃的地方。 您在其他地方使用索引为 4 的范围,但该范围超出了(属性)字符串(?)的范围。您可以在 Xcode 中使用启用异常断点来查看实际发生的位置。
【讨论】:
以上是关于由于未捕获的异常 NSInvalidArgumentException 而终止应用程序,原因:索引无效的主要内容,如果未能解决你的问题,请参考以下文章
由于未捕获的异常而终止应用程序 [UIImageView _isResizable]
由于未捕获的异常“NSInternalInconsistencyException”错误而终止应用程序