2013-11-14 31 views
-1

我是IOS開發新手。當我運行我的應用程序時,出現以下錯誤。任何人都可以幫助我..由於未捕獲異常而終止應用程序NSInvalidArgumentException,原因:索引無效

我已將UITextView放在TableViewCell的內部。而且我已將'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」. 

我在做什麼錯在這裏?

+0

如何顯示代碼而不是描述它。 – Abizern

+0

@Abizern:你現在可以檢查一下嗎? – Kirubachari

回答

1

提供的代碼不是崩潰的地方。 其他地方,你正在使用索引爲4的範圍,但該範圍超出(歸屬)字符串(?)的範圍。您可以使用Xcode中的啓用異常斷點來查看實際發生的位置。

相關問題