my code is:
- (void) tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete){
/* First remove this object from the source */
[self.allRows removeObjectAtIndex:indexPath.row];
/* Then remove the associated cell from the Table View */
[tableView deleteRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
i am getting error as follows
2015-02-16 11:57:32.413 SimpleTable[1590:45462] -[ViewController refreshControl]: unrecognized selector sent to instance 0x7fa1d2d936c0
2015-02-16 11:57:32.415 SimpleTable[1590:45462] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController refreshControl]: unrecognized selector sent to instance 0x7fa1d2d936c0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d738f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d3d1bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010d74004d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010d69827c ___forwarding___ + 988
4 CoreFoundation 0x000000010d697e18 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010db268be -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010db268be -[UIApplication sendAction:to:from:forEvent:] + 75
7 UIKit 0x000000010dc2d410 -[UIControl _sendActionsForEvents:withEvent:] + 467
8 UIKit 0x000000010dc2c7df -[UIControl touchesEnded:withEvent:] + 522
9 UIKit 0x000000010db6c308 -[UIWindow _sendTouchesForEvent:] + 735
10 UIKit 0x000000010db6cc33 -[UIWindow sendEvent:] + 683
11 UIKit 0x000000010db399b1 -[UIApplication sendEvent:] + 246
12 UIKit 0x000000010db46a7d _UIApplicationHandleEventFromQueueEvent + 17370
13 UIKit 0x000000010db22103 _UIApplicationHandleEventQueue + 1961
14 CoreFoundation 0x000000010d66e551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000010d66441d __CFRunLoopDoSources0 + 269
16 CoreFoundation 0x000000010d663a54 __CFRunLoopRun + 868
17 CoreFoundation 0x000000010d663486 CFRunLoopRunSpecific + 470
18 GraphicsServices 0x0000000110d079f0 GSEventRunModal + 161
19 UIKit 0x000000010db25420 UIApplicationMain + 1282
20 SimpleTable 0x000000010cea27d3 main + 115
21 libdyld.dylib 0x000000010fcc8145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I think your TableView may be getting released after you create it and the method ends. You probably need to create an instance variable inside in View controller that references it.
#property (strong, nonatomic) IBOutlet UITableView *tablview;
Then remove the associated cell from the Table View
[self.tablview deleteRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
May help you..
Try this
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//remove the row from data model
[tableData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
Related
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'm trying to create a tableview that the cells contains name, telephone and mail. If the user touches the telephone, the app calls to the phone (click to call). If the user touches the mail, I need to open the mail app with a new email to the "touched address".
First, I'm trying to develop the touchable label that contains an email, but I'm receiving the error "selector sent to instance".
I need to identify the tapgesture, and then, identify if it's an email or telephone, get the text and calls or open mail app.
Current code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
cell.lblEmail.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(labelTap)];
[cell.lblEmail addGestureRecognizer:tapGesture];
return cell;
}
- (void)labelTap:(UIGestureRecognizer *)sender {
UILabel *labelSender = (UILabel*) sender;
NSLog(#"%text: %#", labelSender.text);
}
ERROR:
2015-02-03 12:28:29.726 MyApp[80080:4019203] -[MyAppContactsViewController labelTap]: unrecognized selector sent to instance 0x7ff6d8cb4110
2015-02-03 12:28:29.743 MyApp[80080:4019203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyAppContactsViewController labelTap]: unrecognized selector sent to instance 0x7ff6d8cb4110'
*** First throw call stack:
(
0 CoreFoundation 0x000000010709cf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000106d35bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001070a404d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000106ffc27c ___forwarding___ + 988
4 CoreFoundation 0x0000000106ffbe18 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001059912e6 _UIGestureRecognizerSendActions + 262
6 UIKit 0x000000010598ff89 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 532
7 UIKit 0x0000000105994ba6 ___UIGestureRecognizerUpdate_block_invoke662 + 51
8 UIKit 0x0000000105994aa2 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 254
9 UIKit 0x000000010598ab1d _UIGestureRecognizerUpdate + 2796
10 UIKit 0x0000000105624ff6 -[UIWindow _sendGesturesForEvent:] + 1041
11 UIKit 0x0000000105625c23 -[UIWindow sendEvent:] + 667
12 UIKit 0x00000001055f29b1 -[UIApplication sendEvent:] + 246
13 UIKit 0x00000001055ffa7d _UIApplicationHandleEventFromQueueEvent + 17370
14 UIKit 0x00000001055db103 _UIApplicationHandleEventQueue + 1961
15 CoreFoundation 0x0000000106fd2551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x0000000106fc841d __CFRunLoopDoSources0 + 269
17 CoreFoundation 0x0000000106fc7a54 __CFRunLoopRun + 868
18 CoreFoundation 0x0000000106fc7486 CFRunLoopRunSpecific + 470
19 GraphicsServices 0x0000000109fa59f0 GSEventRunModal + 161
20 UIKit 0x00000001055de420 UIApplicationMain + 1282
21 MyApp 0x00000001040769a3 main + 115
22 libdyld.dylib 0x0000000107a9c145 start + 1
23 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Change this line:
[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(labelTap)];
to
[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(labelTap:)];
This is required because labelTap as a selector is distinct from labelTap:. The former is a selector with no parameters (which doesn't exist, hence the exception), and the latter is the one with 1 parameter, which you have indeed defined.
Vinod, Claus were correct. I changed for UIButton and worked perfectly.
I'm identifying witch mail was selected, with this code: Detecting which UIButton was pressed in a UITableView
I created a separate UITableViewCell and designed it using .xib file and it looks like
My header file for UITableViewCell looks like
#interface MenuTableViewCell : UITableViewCell
#property(nonatomic, weak) IBOutlet UIImageView *menuImage;
#property(nonatomic, weak) IBOutlet UILabel *menuLabel;
#end
and both properties are connected
I tried to use it in my MenuViewController as
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.menuImage.image = [self getImageNameForRow:indexPath.row];
cell.menuLabel.text = self.features[(NSUInteger) indexPath.row];
return cell;
}
and
- (UIImage *)getImageNameForRow:(NSInteger)row {
if (row == 0) {
return [UIImage imageNamed:#"Transaction"];
}
if (row == 1) {
return [UIImage imageNamed:#"Summary"];
}
return [UIImage imageNamed:#"Budget"];
}
when I run my application, it crashes and shows the following on log
2014-08-30 14:51:54.387 pennyapp-ios[37988:70b] -[UITableViewCell menuImage]: unrecognized selector sent to instance 0x10bb1e5e0
2014-08-30 14:51:54.389 pennyapp-ios[37988:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell menuImage]: unrecognized selector sent to instance 0x10bb1e5e0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001023c6495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010212599e objc_exception_throw + 43
2 CoreFoundation 0x000000010245765d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001023b7d8d ___forwarding___ + 973
4 CoreFoundation 0x00000001023b7938 _CF_forwarding_prep_0 + 120
5 pennyapp-ios 0x00000001000044ed -[MenuTableViewController tableView:cellForRowAtIndexPath:] + 141
6 UIKit 0x0000000100904f8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348
7 UIKit 0x00000001008ead5b -[UITableView _updateVisibleCellsNow:] + 2337
8 UIKit 0x00000001008fc721 -[UITableView layoutSubviews] + 207
9 UIKit 0x0000000100890993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
10 QuartzCore 0x0000000104fbc802 -[CALayer layoutSublayers] + 151
11 QuartzCore 0x0000000104fb1369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
12 QuartzCore 0x0000000104fb11ea _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13 QuartzCore 0x0000000104f24fb8 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
14 QuartzCore 0x0000000104f26030 _ZN2CA11Transaction6commitEv + 394
15 UIKit 0x0000000100848e25 _afterCACommitHandler + 128
16 CoreFoundation 0x0000000102391dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
17 CoreFoundation 0x0000000102391d37 __CFRunLoopDoObservers + 391
18 CoreFoundation 0x0000000102371522 __CFRunLoopRun + 946
19 CoreFoundation 0x0000000102370d83 CFRunLoopRunSpecific + 467
20 GraphicsServices 0x00000001036e3f04 GSEventRunModal + 161
21 UIKit 0x0000000100830e33 UIApplicationMain + 1010
22 pennyapp-ios 0x0000000100001353 main + 115
23 libdyld.dylib 0x00000001033655fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I am very new to iOS and can't understand the error message, can some one please help me knowing what am In doing wrong?
There were 2 problems.
I was registering UITableViewCell instead of MenuTableViewCell
I was not registering the nib file I had
After making the change as following things, started to work again.
[self.tableView registerNib:[UINib nibWithNibName:#"MenuTableViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
Thank you for all your answers, they helped me a lot!
Declare an imgearray in interface,then add your array of images,next cellforatindexpath add code for UIImageView
yourcellname.yourimagename.image=[UIImage imagenamed:[yourimagearray objectAtIndexPath.row]];
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] ()