gpt4 book ai didi

ios - 由于未捕获的异常 'NSRangeException' xcode 5 而终止应用程序

转载 作者:行者123 更新时间:2023-11-29 03:28:39 25 4
gpt4 key购买 nike

我在选择器 View 函数中遇到此错误,该函数将其数据从谷歌电子表格获取到文本文件。这是该函数的代码。

{
- (IBAction)clickText:(id)sender

int tag = [(UITextField*)sender tag];
if (tag!=11)
if (tag!=12)
if (tag!=13)
if (tag!=14)
if (tag!=15)
if (tag!=16)
if (tag!=17)
if (tag!=18)
if (tag!=19)


{
[sender resignFirstResponder];
}
self.myPicker.hidden = NO;
selectedTable = tag;
[sender resignFirstResponder];
float yy = 10;
switch (tag) {
case 11: yy = self.txtTgfeet.frame.origin.y + self.myPicker.frame.size.height;
break;
case 12: yy = self.txtTginches.frame.origin.y + self.myPicker.frame.size.height;
break;
case 13: yy = self.txtTgfraction.frame.origin.y + self.myPicker.frame.size.height;
break;
case 14: yy = self.txtBgfeet.frame.origin.y - self.myPicker.frame.size.height;
break;
case 15: yy = self.txtBginches.frame.origin.y - self.myPicker.frame.size.height;
break;
case 16: yy = self.txtBgfraction.frame.origin.y - self.myPicker.frame.size.height;
break;
case 17: yy = self.txtGravity.frame.origin.y - self.myPicker.frame.size.height;
break;
case 18: yy = self.txtBsw.frame.origin.y - self.myPicker.frame.size.height;
break;
case 19: yy = self.txtTemp.frame.origin.y - self.myPicker.frame.size.height;
break;


default:
break;
}

[self.myPicker setFrame:CGRectMake(self.txtTgfeet.frame.origin.x, yy, self.txtTgfeet.frame.size.width, 216)];

[self.ar removeAllObjects];

NSString *theURL = @"https://docs.google.com/spreadsheet/pub?key=0AobIgii9hBGPdDJ3TmgxSkRzVFBKWXVnTWdQcGtyMFE&single=true&gid=9&output=txt";
NSString *theFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:theURL] encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",theFile);
NSArray *theCells = [theFile componentsSeparatedByString:@"\n"];



for (int i=1; i < [theCells count]; i++)
{
// if (i > 0)
{
NSArray *value =[[theCells objectAtIndex:i] componentsSeparatedByString:@"\t"];
[self.ar addObject:[value objectAtIndex:tag+1]];

}
}
[self.myPicker selectRow:0 inComponent:0 animated:NO];
[self.myPicker reloadAllComponents];

此功能在其他应用程序上运行良好,我仅为了我想要此功能的另一个应用程序制作了此功能。现在,当我单击文本字段时,我收到此错误:

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 12 beyond bounds [0 .. 8]'
*** First throw call stack:
(
0 CoreFoundation 0x01b575e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018da8b6 objc_exception_throw + 44
2 CoreFoundation 0x01af84e6 -[__NSArrayM objectAtIndex:] + 246
3 TGC 0x000080ba -[MainViewController clickText:] + 4602
4 libobjc.A.dylib 0x018ec81f -[NSObject performSelector:withObject:] + 70
5 UIKit 0x0043d0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
6 UIKit 0x0043d04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
7 UIKit 0x005350c1 -[UIControl sendAction:to:forEvent:] + 66
8 UIKit 0x00535484 -[UIControl _sendActionsForEvents:withEvent:] + 577
9 UIKit 0x00b222ae -[UITextField willAttachFieldEditor:] + 685
10 UIKit 0x0053aeb5 -[UIFieldEditor becomeFieldEditorForView:] + 927
11 UIKit 0x00b193a3 -[UITextField _becomeFirstResponder] + 160
12 UIKit 0x00594ef5 -[UIResponder becomeFirstResponder] + 400
13 UIKit 0x0049819b -[UIView(Hierarchy) becomeFirstResponder] + 114
14 UIKit 0x00b18e43 -[UITextField becomeFirstResponder] + 51
15 UIKit 0x007bd551 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 135
16 UIKit 0x007bfaa2 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2640
17 UIKit 0x007b3e8c _UIGestureRecognizerSendActions + 230
18 UIKit 0x007b2b00 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
19 UIKit 0x007b456d -[UIGestureRecognizer _delayedUpdateGesture] + 60
20 UIKit 0x007b7acd ___UIGestureRecognizerUpdate_block_invoke + 57
21 UIKit 0x007b7a4e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
22 UIKit 0x007ae148 _UIGestureRecognizerUpdate + 199
23 UIKit 0x0047a19a -[UIWindow _sendGesturesForEvent:] + 1291
24 UIKit 0x0047b0ba -[UIWindow sendEvent:] + 1030
25 UIKit 0x0044ee86 -[UIApplication sendEvent:] + 242
26 UIKit 0x0043918f _UIApplicationHandleEventQueue + 11421
27 CoreFoundation 0x01ae083f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
28 CoreFoundation 0x01ae01cb __CFRunLoopDoSources0 + 235
29 CoreFoundation 0x01afd29e __CFRunLoopRun + 910
30 CoreFoundation 0x01afcac3 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x01afc8db CFRunLoopRunInMode + 123
32 GraphicsServices 0x031bb9e2 GSEventRunModal + 192
33 GraphicsServices 0x031bb809 GSEventRun + 104
34 UIKit 0x0043bd3b UIApplicationMain + 1225
35 TGC 0x00002d62 main + 130
36 libdyld.dylib 0x022fd725 start + 0
37 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

这里的问题是什么?

最佳答案

这里明确提到[__NSArrayM objectAtIndex:]: index 12 beyond bounds [0 .. 8]'

您正在尝试访问第 12 个 [索引 12 且数组仅包含 0 到 8 个对象] 元素,该元素不存在,因此应用程序崩溃。

在行下方使用断点检查,

 [self.ar addObject:[value objectAtIndex:tag+1]];

关于ios - 由于未捕获的异常 'NSRangeException' xcode 5 而终止应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20116910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com