简体   繁体   English

由于未捕获的异常'NSRangeException'终止应用程序,原因:'*** - [NSMutableArray objectAtIndex:]:索引1超出边界[0 .. 0]'

[英]Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

i'm receiving the following errors, very new to iphone dev and objective C. I am very much willing to send over my project for someone to have a look, i'm running in circles and have no idea what to do next! 我收到了以下错误,非常新的iphone开发和目标C.我非常愿意发送我的项目给某人看看,我在圈子里跑,不知道接下来该做什么!

2010-11-10 19:38:07.822 iShisha[2698:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** Call stack at first throw:
(
 0   CoreFoundation                      0x025f9b99 __exceptionPreprocess + 185
 1   libobjc.A.dylib                     0x0274940e objc_exception_throw + 47
 2   CoreFoundation                      0x025ef695 -[__NSArrayM objectAtIndex:] + 261
 3   iShisha                             0x00003dc5 -[MapViewController tableView:cellForRowAtIndexPath:] + 1262
 4   UIKit                               0x0032dd6f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 619
 5   UIKit                               0x00323e02 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
 6   UIKit                               0x00338774 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
 7   UIKit                               0x003307ec -[UITableView layoutSubviews] + 242
 8   QuartzCore                          0x046d7481 -[CALayer layoutSublayers] + 177
 9   QuartzCore                          0x046d71b1 CALayerLayoutIfNeeded + 220
 10  QuartzCore                          0x046d02e0 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 302
 11  QuartzCore                          0x046d0040 _ZN2CA11Transaction6commitEv + 292
 12  QuartzCore                          0x04700ebb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
 13  CoreFoundation                      0x025daf4b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
 14  CoreFoundation                      0x0256fb27 __CFRunLoopDoObservers + 295
 15  CoreFoundation                      0x02538ce7 __CFRunLoopRun + 1575
 16  CoreFoundation                      0x02538350 CFRunLoopRunSpecific + 208
 17  CoreFoundation                      0x02538271 CFRunLoopRunInMode + 97
 18  GraphicsServices                    0x02ed800c GSEventRunModal + 217
 19  GraphicsServices                    0x02ed80d1 GSEventRun + 115
 20  UIKit                               0x002caaf2 UIApplicationMain + 1160
 21  iShisha                             0x00001de8 main + 102
 22  iShisha                             0x00001d79 start + 53
)
terminate called after throwing an instance of 'NSException'

[Session started at 2010-11-10 19:38:15 +0000.]
Pending breakpoint 1 - ""MapViewController.m":204" resolved
Pending breakpoint 2 - ""MapViewController.m":317" resolved
Pending breakpoint 3 - "objc_exception_throw" resolved
(gdb) 

In CocoaTouch, tables have a delegate and a data source. 在CocoaTouch中,表具有委托和数据源。 The delegate sends and receives messages for the table view, and the data source controls the information that goes in the table and the table's headers and footers. 委托发送和接收表视图的消息,数据源控制表中的信息以及表的页眉和页脚。 The data source tells the table how many rows to draw, how many sections, what to put as the section titles, etcetera. 数据源告诉表格要绘制多少行,有多少部分,要放置的部分标题等等。

The table view queries the data source for how many rows to draw via the 表视图通过查询数据源查询要绘制的行数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

method. 方法。 Then, in the 然后,在

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

method, the tableView asks for a cell to populate the table from the data source. 方法,tableView要求一个单元格从数据源填充表。 When programming for the iPhone, tables are mostly populated by an array, a single variable (object) that contains many other variables (objects). 在为iPhone编程时,表主要由数组填充,一个变量(对象)包含许多其他变量(对象)。 You tell an array what object you want, by asking 通过询问,告诉数组你想要什么对象

object = [array objectAtIndex:INTEGER]; //where INTEGER is an unsigned (zero or greater, no minus)

what happened, is that your data source is expecting X number of objects for the table, and there are XY available. 发生了什么,是你的数据源期望表的X个对象,并且有XY可用。 If it thinks there are 10, but there are only 9, when the table asks for the 10th object, you get a crash because there is no object to give. 如果它认为有10个,但只有9个,当表要求第10个对象时,你会因为没有任何对象而崩溃。

look in your code for hte line 查看代码中的hte行

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

and see what that code is. 并查看该代码是什么。 Chances are you're providing the wrong data there. 你有可能在那里提供错误的数据。

Good luck 祝好运

I don't think there is a need to change from static to dynamic cells for this one (there are cases where you may need the cells to be static). 我认为不需要从静态单元格转换为动态单元格(有些情况下您可能需要单元格是静态的)。 What may have caused this problem is that you may have only named 0 sections for your table view in the "Attributes Inspector" section in the storyboard. 可能导致此问题的原因是您可能只在故事板的“属性检查器”部分中为表视图命名了0个部分。 All you need to do is increase this number to 1 or as many sections as you may need. 您需要做的就是将此数字增加到1或尽可能多的部分。

Well I think that's what @styfle's problem was. 好吧,我认为这就是@ styfle的问题所在。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由于未捕获的异常“ NSRangeException”而终止应用程序,原因:“ ***-[NSMutableArray objectAtIndex:]:索引26超出范围[0 .. 0]” - Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 26 beyond bounds [0 .. 0]' ***由于未捕获的异常'NSRangeException'而终止应用程序,原因:'***-[NSMutableArray objectAtIndex:]:索引1超出范围[0 .. 0]' - *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]' ***由于未捕获的异常'NSRangeException'而终止应用程序,原因:'*** - *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** 'NSRangeException',原因:'* -[__NSArrayM objectAtIndex:]:索引 2 超出范围 [0 .. 1]' - 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]' iPhone-ReplaceScene错误:由于未捕获的异常'NSRangeException',正在终止应用程序,原因:'***-[NSMutableArray replaceObjectAtIndex:withObject:] - iphone - replaceScene error:Terminating app due to uncaught exception 'NSRangeException',reason:'***-[NSMutableArray replaceObjectAtIndex:withObject:] 因未捕获的异常“NSRangeException”而终止应用程序会使Range或index超出范围 - Terminating app due to uncaught exception 'NSRangeException' gives Range or index out of bounds' 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[NSDecimalNumber objectAtIndex:] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber objectAtIndex:] 异常“ NSRangeException”,原因:“ ***-[__ NSArray0 objectAtIndex:]:空NSArray的索引0超出范围” - exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray' iOS:致命异常:NSRangeException ***-[__ NSArrayM objectAtIndex:]:索引1超出范围[0 .. 0] - iOS: Fatal Exception: NSRangeException *** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0] Xcode - 由于未捕获的异常'NSRangeException'而终止应用程序 - Xcode - Terminating app due to uncaught exception 'NSRangeException'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM