I got this error message.
GoogleAnalytics 2.0b3 void GAIUncaughtExceptionHandler(NSException *)
(GAIUncaughtExceptionHandler.m:41): Uncaught exception: *** -[__NSArrayM objectAtIndex:]:
index 2 beyond bounds [0 .. 1]
libc++abi.dylib: terminate_handler unexpectedly threw an exception
When I trying to zoom page, I got crash and this error in crashlytics.
Thread : Fatal Exception: NSRangeException
0 CoreFoundation 0x31a202a3 __exceptionPreprocess + 162
1 libobjc.A.dylib 0x3974897f objc_exception_throw + 30
2 CoreFoundation 0x3196bb75 -[__NSArrayM objectAtIndex:] + 164
3 TestApp 0x000b1bfb -[EpisodeTableViewDelegate
tableView:didSelectRowAtIndexPath:] (EpisodeTableViewDelegate.m:155)
4 UIKit 0x338ea28d -[UITableView
_selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 876
5 UIKit 0x3396cf81 -[UITableView
_userSelectRowAtPendingSelectionIndexPath:] + 156
6 Foundation 0x3232e277 __NSFireDelayedPerform + 450
7 CoreFoundation 0x319f55df __
CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
8 CoreFoundation 0x319f5291 __CFRunLoopDoTimer + 272
9 CoreFoundation 0x319f3f01 __CFRunLoopRun + 1232
10 CoreFoundation 0x31966ebd CFRunLoopRunSpecific + 356
11 CoreFoundation 0x31966d49 CFRunLoopRunInMode + 104
12 GraphicsServices 0x3553f2eb GSEventRunModal + 74
13 UIKit 0x3387c301 UIApplicationMain + 1120
14 Tapastic 0x00075cb7 main (main.m:16)
15 Tapastic 0x000753b8 start
My code is as below:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if (indexPath.section == 1) {
Episode *episode = [[Episode alloc] init];
[episode bindProperties:[self.pager.contents objectAtIndex:indexPath.row]];
[self.baseController performSegueWithIdentifier:SEGUE_EPISODE_VIEW sender:episode];
}
}
I cannot solve this problem. How can I fix it? If possible, please let know.
Thanks in advance.
You're calling objectAtIndex on the episode array with index 2, when there are only two objects in the array. Array objects are numbered starting with 0, so an array with two objects only has elements 0 and 1.
It sounds like you're not setting up your UITableView correctly. If there are only two objects in the array backing the table, there should only be two rows in the table.
Related
I have Maintableview(a UIViewController) with contents and detailview(a UIViewController) that show detail for each of cells in Maintableview.
I have added a "favorite" button in "detailview" that user can add to Favoritetableview(a UIViewController) and every thing work fine.
Now I have added "add to favorite" in Maintableview with swipe to left.
It adds contents successfully to Favoritetableview but when I touch that cell in Favoritetableview the app crashes.
Below is the console logs for the crash:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a871d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a2e3deb objc_exception_throw + 48
2 CoreFoundation 0x000000010a75a934 -[__NSArrayI objectAtIndex:] + 164
3 iranbirds 0x00000001075cf672 -[FavoriteTableViewController prepareForSegue:sender:] + 530
4 UIKit 0x00000001090c55d5 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 369
5 UIKit 0x00000001090c5433 -[UIStoryboardSegueTemplate _perform:] + 82
6 UIKit 0x0000000108b1b5f8 -[UIViewController performSegueWithIdentifier:sender:] + 99
7 iranbirds 0x00000001075cf42d -[FavoriteTableViewController tableView:didSelectRowAtIndexPath:] + 189
8 UIKit 0x0000000108ac51c6 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1887
9 UIKit 0x0000000108ac541b -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 388
10 UIKit 0x0000000108989f62 _runAfterCACommitDeferredBlocks + 317
11 UIKit 0x000000010899de4c _cleanUpAfterCAFlushAndRunDeferredBlocks + 95
12 UIKit 0x00000001089aa147 _afterCACommitHandler + 90
13 CoreFoundation 0x000000010a796c37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
14 CoreFoundation 0x000000010a796ba7 __CFRunLoopDoObservers + 391
15 CoreFoundation 0x000000010a78c7fb __CFRunLoopRun + 1147
16 CoreFoundation 0x000000010a78c0f8 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x000000010be6bad2 GSEventRunModal + 161
18 UIKit 0x000000010897df09 UIApplicationMain + 171
19 iranbirds 0x00000001075d32ef main + 111
20 libdyld.dylib 0x000000010ba6492d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
favorite table view:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = (NSIndexPath *)sender;
Favorite *fav = (Favorite *)[self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *combinedName = fav.name;
if ([segue.identifier isEqualToString:#"FavoriteBirdDetail"])
{
GeneralViewController *detailViewController = (GeneralViewController*)[segue destinationViewController];
detailViewController.birdName = [combinedName componentsSeparatedByString:#"^"][0];;
detailViewController.sciName = [combinedName componentsSeparatedByString:#"^"][1];;
detailViewController.managedOjbectContext = self.managedOjbectContext;
}
}
This line cause error:
detailViewController.sciName = [combinedName componentsSeparatedByString:#"^"][1];
Any help would be appreciated.
detailViewController.sciName = [combinedName componentsSeparatedByString:#"^"][1];
Well, look at this code - you are getting second object from an array by subscript syntax. And the code would work if an array contains at least 2 items.
It looks like your array contains zero or one element, that is why app crashes when you try to get an element by 1 index - [1], which means the second element.
To prevent crash you should check an array count property before:
NSArray *anArray = [combinedName componentsSeparatedByString:#"^"];
if anArray.count >= 2 {
detailViewController.sciName = anArray[1];
}
I have a static UItableView. In one of the cells, I have a dynamic prototype UITableView. Here is the code I implemented:
In viewDidLoad:
self.tagsArray = [[NSArray alloc] initWithObjects:#"hey", #"what", #"ola", #"dada", #"hoster", #"umi", nil];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.tableView == tableView ? 2 : 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.tableView == tableView)
return (section == 0) ? 3 : 2;
else
return [self.tagsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (self.tableView == tableView) {
cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
else {
cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
[cell.textLabel setText:self.tagsArray [indexPath.row]];
}
return cell;
}
When I run the app, everything works fine. But when I start scrolling on the inner tableView (the dynamic prototype one), then I get the following error:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** First throw call stack:
(
0 CoreFoundation 0x00000001012a7c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000100f40bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010119e17e -[__NSArrayI objectAtIndex:] + 190
3 UIKit 0x0000000101e12132 -[UITableViewDataSource tableView:indentationLevelForRowAtIndexPath:] + 106
4 UIKit 0x00000001019dc1f9 __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1711
5 UIKit 0x000000010195a68e +[UIView(Animation) performWithoutAnimation:] + 65
6 UIKit 0x00000001019dbb3b -[UITableView _configureCellForDisplay:forIndexPath:] + 312
7 UIKit 0x00000001019e3a41 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 533
8 UIKit 0x00000001019c2248 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2853
9 UIKit 0x00000001019d88a9 -[UITableView layoutSubviews] + 210
10 UIKit 0x0000000101962a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
11 QuartzCore 0x0000000100934ec2 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x00000001009296d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x0000000100929546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000100895886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
15 QuartzCore 0x0000000100896a3a _ZN2CA11Transaction6commitEv + 462
16 QuartzCore 0x00000001008970eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
17 CoreFoundation 0x00000001011daca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x00000001011dac00 __CFRunLoopDoObservers + 368
19 CoreFoundation 0x00000001011d0a33 __CFRunLoopRun + 1123
20 CoreFoundation 0x00000001011d0366 CFRunLoopRunSpecific + 470
21 GraphicsServices 0x000000010510da3e GSEventRunModal + 161
22 UIKit 0x00000001018e2900 UIApplicationMain + 1282
23 myApp 0x00000001004cf51f main + 111
24 libdyld.dylib 0x0000000102cfe145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I don't know what the above error means, but I think that it's not creating new cells for some reason, and because of that, it has a conflict with the number of cells to display, so it crashes with the above error.
Why isn't the inner tableView creating new cells, and what can I do to fix it?
What the error is telling you is that you tried to access an element that doesn't exist.
Your data array only has 2 elements, but you are hardcoding the amount of cells you want to create (3) so when it looks for the 3rd element to create the cell it crashes because is not existent.
I have an NSMutableArray that I have build up that consists or holds a NSMutableDictionary.
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
self.userNameArray = [NSMutableArray arrayWithArray:[userDefaults arrayForKey:#"userNameTextArray"]];
NSMutableArray *arrayToAdd = [[NSMutableArray alloc] init];
for (id object in self.userNameArray) {
[arrayToAdd addObject:#"Negative"];
}
self.namesDictionary = [#{ #"userNameText" : self.categoriesMutableNameArray, #"selectedCellState" : arrayToAdd}mutableCopy];
self.namesFinalArr = [[NSMutableArray alloc] init];
self.namesDictMutableDict = [NSMutableDictionary dictionaryWithDictionary:self.namesDictionary];
[self.namesFinalArr addObject:self.namesDictMutableDict];
The result in my NSlog of the above code is like this:
(
{
selectedCellState = (
Negative,
Negative,
Negative,
Negative,
Negative,
Negative,
Negative,
Negative,
Negative,
Negative,
Negative,
Negative,
Negative,
Negative
);
userNameText = (
"userText - Text",
"userText1 - Text1",
"userText2 - Text2",
"userText3 - Text3",
"userText4 - Text4",
"userText5 - Text5",
"userText6 - Text6",
"userText7 - Text7",
"userText8 - Text8",
"userText9 - Text9",
"userText10 - Text10",
"userText11 - Text11",
"userText12 - Text12",
"userText13 - Text13"
);
}
)
I am using a UITableview and I populate the UITableview with self.namesFinalArr . in the CellForRow method like this and it works:
labelForTableCell.text = [[[self.namesFinalArr objectAtIndex:0] objectForKey:#"userNameText"]objectAtIndex:indexPath.row];
This populates my UITableview with the data under userNameText in self.namesFinalArr
I am trying to enable or disable an image on a cell when it is selected and I use the didDeselectRowAtIndexPath and didselectRowAtIndexPath methods to show and hide a UImageview
This works but I am trying to update selectedCellState in self.namesFinalArr at the index row or row that was pressed but I get the following error.
In the didselectRowAtIndexPath method I do something like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedRows = [self.tableView indexPathsForSelectedRows];
[[[[self.namesFinalArr objectAtIndex:0] objectForKey:#"selectedCellState"]objectAtIndex:indexPath.row] setValue:#"Positive" forKey:#"selectedCellState"];
}
When trying to change the array value and index row I get a error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFConstantString 0x23fef0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key selectedCellState.'
*** First throw call stack:
(
0 CoreFoundation 0x020c75e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01e4a8b6 objc_exception_throw + 44
2 CoreFoundation 0x021576a1 -[NSException raise] + 17
3 Foundation 0x0075d9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x006c9cfb _NSSetUsingKeyValueSetter + 88
5 Foundation 0x006c9253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Piccing 0x0004880c -[PiccImageCategoriesViewController tableView:didSelectRowAtIndexPath:] + 828
7 UIKit 0x010a77b1 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1513
8 UIKit 0x010a7924 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
9 UIKit 0x010ab908 __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
10 UIKit 0x00fe2183 ___afterCACommitHandler_block_invoke + 15
11 UIKit 0x00fe212e _applyBlockToCFArrayCopiedToStack + 403
12 UIKit 0x00fe1f5a _afterCACommitHandler + 532
13 CoreFoundation 0x0208f4ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
14 CoreFoundation 0x0208f41f __CFRunLoopDoObservers + 399
15 CoreFoundation 0x0206d344 __CFRunLoopRun + 1076
16 CoreFoundation 0x0206cac3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x0206c8db CFRunLoopRunInMode + 123
18 GraphicsServices 0x027779e2 GSEventRunModal + 192
19 GraphicsServices 0x02777809 GSEventRun + 104
20 UIKit 0x00fc5d3b UIApplicationMain + 1225
21 Piccing 0x000138cd main + 141
22 libdyld.dylib 0x02f4d70d start + 1
23 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
In this case,there is one array which contains two dictionary each contains array and you are suppose to change the values in array and you should used this method to change the value
[[[self.namesFinalArr objectAtIndex:0] objectForKey:#"selectedCellState"] replaceObjectAtIndex:indexPath.row withObject:#"Positive"];
I am trying to get the contents of my UITableViewCell before I delete it from my Core Data model in order to act on its contents. If there is only one item in the Core Data model and I go to delete it from my UITableView, the app will only sometimes throw an error of 2014-01-05 11:10:26.189 Nibbles[43609:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFArray objectAtIndex:]: index (2008) beyond bounds (1)'
My biggest confusion is that this only happens with one item in the UITableView and doesn't happen 100% of the time. If you need to see any other code, please let me know.
Here is the code I am using. The bolded line is the one causing the error since it never makes it past there to NSLog to the console.
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSLog(#"Delete button pressed!");
FoodListCell *cell = (FoodListCell*)[tableView cellForRowAtIndexPath:indexPath];
NSLog(#"DEBUG | Selected Cell: %#", cell);
NSString *foodOrActivity = cell.foodNameLabel.text;
NSString *points = cell.foodPointsLabel.text;
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
[[self.fetchedResultsController objectAtIndexPath:indexPath] MR_deleteInContext:localContext];
[localContext MR_saveOnlySelfAndWait];
NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
NSManagedObject *deleteObject = [_fetchedResultsController objectAtIndexPath:path];
[managedObjectContext deleteObject:deleteObject];
}
And here is the full stack trace:
2014-01-05 11:10:26.189 Nibbles[43609:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFArray objectAtIndex:]: index (2008) beyond bounds (1)'
*** First throw call stack:
(
0 CoreFoundation 0x01cd45e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01a578b6 objc_exception_throw + 44
2 CoreFoundation 0x01cd43bb +[NSException raise:format:] + 139
3 CoreData 0x00280755 -[_PFArray objectAtIndex:] + 133
4 CoreData 0x002f9778 -[_PFMutableProxyArray objectAtIndex:] + 120
5 CoreData 0x00382c1f -[NSFetchedResultsController objectAtIndexPath:] + 255
6 Nibbles 0x0000660d -[FoodListViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 685
7 UIKit 0x008b5ba3 -[UITableView animateDeletionOfRowWithCell:] + 107
8 UIKit 0x00a35695 -[UITableViewCell _swipeDeleteButtonPushed] + 70
9 libobjc.A.dylib 0x01a69874 -[NSObject performSelector:withObject:withObject:] + 77
10 UIKit 0x007c70c2 -[UIApplication sendAction:to:from:forEvent:] + 108
11 UIKit 0x007c704e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
12 UIKit 0x008bf0c1 -[UIControl sendAction:to:forEvent:] + 66
13 UIKit 0x008bf484 -[UIControl _sendActionsForEvents:withEvent:] + 577
14 UIKit 0x008be733 -[UIControl touchesEnded:withEvent:] + 641
15 UIKit 0x00b39c7f _UIGestureRecognizerUpdate + 7166
16 UIKit 0x0080419a -[UIWindow _sendGesturesForEvent:] + 1291
17 UIKit 0x008050ba -[UIWindow sendEvent:] + 1030
18 UIKit 0x007d8e86 -[UIApplication sendEvent:] + 242
19 UIKit 0x007c318f _UIApplicationHandleEventQueue + 11421
20 CoreFoundation 0x01c5d83f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
21 CoreFoundation 0x01c5d1cb __CFRunLoopDoSources0 + 235
22 CoreFoundation 0x01c7a29e __CFRunLoopRun + 910
23 CoreFoundation 0x01c79ac3 CFRunLoopRunSpecific + 467
24 CoreFoundation 0x01c798db CFRunLoopRunInMode + 123
25 GraphicsServices 0x0285e9e2 GSEventRunModal + 192
26 GraphicsServices 0x0285e809 GSEventRun + 104
27 UIKit 0x007c5d3b UIApplicationMain + 1225
28 Nibbles 0x000236ad main + 141
29 libdyld.dylib 0x031b470d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The conventional pattern is to access the model (not through a table cell, but directly from the model). Do whatever you need to do with it, then remove it from your model, then remove it from your table...
The error implies that the localContext being accessed this method is different from (or is in a different state than) the MOC that reports the number of items in the model (used in numberOfRowsInSection:)
Before moving on to recording that deleted object's state, or deleting it. Fix the code that gets that object and just NSLog it. The code that gets that object should exactly match the code that gets it in your cellForRowAtIndexPath:, and the MOC used there should exactly match the numberOfRowsInSection: MOC.
NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
NSManagedObject *deleteObject = [_fetchedResultsController objectAtIndexPath:path];
[managedObjectContext deleteObject:deleteObject];
Here you are getting the index path for the row in section 0 and deleting it.
You already have the index path for the row/cell/section that you want to delete, so why are you trying to delete that row only in section 0?
Try a breakpoint at this line and add some logging to show what row in section 0 is trying to be deleted.
My developing iOS application is sometimes terminated after the method addSubview: is called in the application delegate (but I'm not sure removeFromSuperview: also involved):
[self.tabBarController.view removeFromSuperview];
[self.window addSubview:navigationController.view];
What that showed in the log is:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x019b75a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01c41313 objc_exception_throw + 44
2 CoreFoundation 0x019ad0a5 -[__NSArrayM objectAtIndex:] + 261
3 <app_name> 0x000186dd -[TableViewController tableView:numberOfRowsInSection:] + 205
4 UIKit 0x00a742b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834
5 UIKit 0x00a71eb1 -[UITableViewRowData numberOfRowsInSection:] + 110
6 UIKit 0x00b60807 -[UISearchDisplayController _updateNoSearchResultsMessageVisiblity] + 115
7 Foundation 0x01029669 _nsnote_callback + 145
8 CoreFoundation 0x0198f9f9 __CFXNotificationPost_old + 745
9 CoreFoundation 0x0190e93a _CFXNotificationPostNotification + 186
10 Foundation 0x0101f20e -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
11 UIKit 0x008df649 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 4581
12 UIKit 0x008d9254 -[UIWindow _setRotatableViewOrientation:duration:force:] + 89
13 UIKit 0x008db38f -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 794
14 UIKit 0x008d9081 -[UIWindow setDelegate:] + 252
15 UIKit 0x00964dee -[UIViewController _tryBecomeRootViewControllerInWindow:] + 106
16 UIKit 0x00975340 -[UINavigationController viewDidMoveToWindow:shouldAppearOrDisappear:] + 72
17 UIKit 0x008f0e4b -[UIView(Internal) _didMoveFromWindow:toWindow:] + 918
18 UIKit 0x008efa60 -[UIView(Hierarchy) _postMovedFromSuperview:] + 166
19 UIKit 0x008e8750 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1080
20 UIKit 0x008e6aa3 -[UIView(Hierarchy) addSubview:] + 57
21 <app_name> 0x00004971 -[AppDelegate requestFinished:] + 993
22 <app_name> 0x0003e65b -[ASIHTTPRequest reportFinished] + 171
23 Foundation 0x0103e94e __NSThreadPerformPerform + 251
24 CoreFoundation 0x019988ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
25 CoreFoundation 0x018f688b __CFRunLoopDoSources0 + 571
26 CoreFoundation 0x018f5d86 __CFRunLoopRun + 470
27 CoreFoundation 0x018f5840 CFRunLoopRunSpecific + 208
28 CoreFoundation 0x018f5761 CFRunLoopRunInMode + 97
29 GraphicsServices 0x01db11c4 GSEventRunModal + 217
30 GraphicsServices 0x01db1289 GSEventRun + 115
31 UIKit 0x008c5c93 UIApplicationMain + 1160
32 <app_name> 0x00002a30 main + 192
33 <app_name> 0x00002255 start + 53
)
terminate called throwing an exception
How can I find out the reason why the app is terminated by this log and solve it? Thank you.
Note: Edit 1 and Edit 2 were removed.
Edit 3: This implemented code of tableView:numberOfRowsInSection: method works for me:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
if (filteredSectionListOfAddressBook && filteredSectionListOfAddressBook.count)
{
return [[filteredSectionListOfAddressBook objectAtIndex:section] count];
}
else
{
return 0;
}
}
else if (tableView == self.tableView)
{
if (sectionListOfAddressBook && sectionListOfAddressBook.count)
{
return [[sectionListOfAddressBook objectAtIndex:section] count];
}
else
{
return 0;
}
}
return 0;
}
In your stack trace - there is a tableview - you need to ensure that there is data to populate the table. Thats where this error is coming from
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array
You could for the moment ensure there is no data by making sure that
tableView:numberOfRowsInSection: returns 0;
Have you implemented the TableViews delegate methods?
Read about it here About Table Views in iOS-Based Applications
here UITableViewDataSource Protocol Reference
and here UITableViewDelegate Protocol Reference
I just ran into a problem like this in my code, and I found that it was caused by the search delegate holding on to the search bar and the table ref. If a set these properties to nil in searchDisplayControllerDidEndSearch then it got rid of the problem. It was likely caused by a circular ref loop. The stack trace looked like so:
[__NSArrayM _updateNoSearchResultsMessageVisiblity]: unrecognized selector sent to instance 0x21c350
#0 0x3369a1c8 in objc_exception_throw ()
#1 0x338b5aca in -[NSObject doesNotRecognizeSelector:] ()
#2 0x338b4944 in __forwarding__ ()
#3 0x3380f680 in _forwarding_prep_0__ ()
#4 0x30e5aff8 in -[UISearchResultsTableView _numberOfRowsDidChange] ()
#5 0x30d6c3b2 in -[UITableView noteNumberOfRowsChanged] ()
#6 0x30d6bf4e in -[UITableView reloadData] ()