Deleting a row causes app to end; no console output - iphone

I've got a UITableViewController with a bunch of random items in it. I want to be able to add items to it, and delete items from it. I have a UITextField in the first section header, so you can type in a word/phrase and add it to the list.
You can delete words from the list without issue, however, if you add a word to the list, then try to delete it, the app ends and returns to the home screen; nothing appears in the console.
I'm not sure where the problem lies. Here's the addNewWord method I've been using:
- (void)addNewWord
{
NSString *newWord = [textField text];
[array insertObject:newWord atIndex:0];
NSLog(#"%d", [array count]);
[textField setText:#""];
[[self tableView] reloadData];
}
And here is the -(void) tableView:commitEditingStyle:forRowAtIndexPath method
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[array removeObjectAtIndex:[indexPath row]];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationRight];
[tableView endUpdates];
}
NSLog(#"%d", [array count]);
}
That's all I've come up with as to where the problem might be, which is also why I'm stuck.
Any insight is greatly appreciated. Thank you very much!
-Edit: Added [tableView beginUpdates]; and [tableView endUpdates]; same results. Any other ideas?
-Edit2: When I added the [tableView beginUpdates]; and [tableView endUpdates];, I get an exception. Here's the console output:
2010-09-30 05:56:40.172 DictionaryWordsTest[2350:207] *** Assertion failure in
-[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/
UIKit-1262.60.3/UITableView.m:920
2010-09-30 05:56:40.175 DictionaryWordsTest[2350:207] *** Terminating app
due to uncaught exception 'NSInternalInconsistencyException', reason:
'Invalid update: invalid number of rows in section 0. The number of rows
contained in an existing section after the update (17) must be equal to the
number of rows contained in that section before the update (17),
plus or minus the number of rows inserted or deleted from that section
(0 inserted, 1 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x02486b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x025d640e objc_exception_throw + 47
2 CoreFoundation 0x0243f238 +[NSException raise:format:arguments:] + 136
3 Foundation 0x000b2e37 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x00332d37 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8719
5 UIKit 0x00322a01 -[UITableView endUpdates] + 42
6 DictionaryWordsTest 0x00002a73 -[DictionaryViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 140
7 UIKit 0x0031f96d -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
8 UIKit 0x002b87f8 -[UIApplication sendAction:to:from:forEvent:] + 119
9 UIKit 0x00343de0 -[UIControl sendAction:to:forEvent:] + 67
10 UIKit 0x00346262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
11 UIKit 0x00344e0f -[UIControl touchesEnded:withEvent:] + 458
12 UIKit 0x002dc3d0 -[UIWindow _sendTouchesForEvent:] + 567
13 UIKit 0x002bdcb4 -[UIApplication sendEvent:] + 447
14 UIKit 0x002c29bf _UIApplicationHandleEvent + 7672
15 GraphicsServices 0x02d66822 PurpleEventCallback + 1550
16 CoreFoundation 0x02467ff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
17 CoreFoundation 0x023c8807 __CFRunLoopDoSource1 + 215
18 CoreFoundation 0x023c5a93 __CFRunLoopRun + 979
19 CoreFoundation 0x023c5350 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x023c5271 CFRunLoopRunInMode + 97
21 GraphicsServices 0x02d6500c GSEventRunModal + 217
22 GraphicsServices 0x02d650d1 GSEventRun + 115
23 UIKit 0x002c6af2 UIApplicationMain + 1160
24 DictionaryWordsTest 0x00001f58 main + 102
25 DictionaryWordsTest 0x00001ee9 start + 53
)
terminate called after throwing an instance of 'NSException'

You need to wrap your -[tableView deleteRowsAtIndexPaths] call with [tableView beginUpdates] and [tableView endUpdates].

Oddly enough, the answer ended up being something other than what I had expected. I'm not sure what the difference is, and why I was getting no console output, but here's what I ended up doing.
In addNewWord, instead of using reloadData, I used these methods to reload the tableView, and insert the word at the top (So I didn't have to scroll to the bottom of the view to see the new word):
- (void)addNewWord
{
[[self tableView] beginUpdates];
NSString *newWord = [textField text];
[array insertObject:newWord atIndex:0];
[textField setText:#""];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[[self tableView] endUpdates];
}
Then, I think the key is, that addNewWord isn't called from:
[textField addTarget:self action:#selector(addNewWord) forControlEvents:UIControlEventEditingDidEndOnExit];
But, I added a button next to my textfield that calls it. Everything works now.

Related

Viewcontroller length unrecognized selector sent to instance in iphone

My application crashing ans showing following in console. How to remove this exception???
2011-11-25 17:47:56.519 ShowroomLocator[1482:707] -[ShowroomLocatorViewController length]: unrecognized selector sent to instance 0x164860
2011-11-25 17:47:56.541 ShowroomLocator[1482:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [ShowroomLocatorViewController length]: unrecognized selector sent to instance 0x164860'
*** Call stack at first throw:
(
0 CoreFoundation 0x308aa64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3400bc5d objc_exception_throw + 24
2 CoreFoundation 0x308ae1bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x308ad649 ___forwarding___ + 508
4 CoreFoundation 0x30824180 _CF_forwarding_prep_0 + 48
5 UIKit 0x35dcfed1 - [UITableView(UITableViewInternal) _delegateWantsHeaderForSection:] + 228
6 UIKit 0x35dcf2db -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 78
7 UIKit 0x35dcf225 -[UITableViewRowData numberOfRows] + 72
8 UIKit 0x35dcec73 -[UITableView noteNumberOfRowsChanged] + 82
9 UIKit 0x35dce7f7 -[UITableView reloadData] + 582
10 HettichShowroomLocator 0x00003487 - [ShowroomLocatorViewController viewWillAppear:] + 50
11 UIKit 0x35dbf1d9 -[UIViewController viewWillMoveToWindow:] + 64
12 UIKit 0x35d9e179 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 132
13 UIKit 0x35d83a59 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 228
14 UIKit 0x35d8396b -[UIView(Hierarchy) addSubview:] + 22
15 UIKit 0x35db335f -[UIWindow addRootViewControllerViewIfPossible] + 202
16 UIKit 0x35daf333 -[UIWindow _setHidden:forced:] + 182
17 UIKit 0x35db328f -[UIWindow _orderFrontWithoutMakingKey] + 18
18 UIKit 0x35dc1c61 -[UIWindow makeKeyAndVisible] + 16
19 ShowroomLocator 0x0000285b - [ShowroomLocatorAppDelegate application:didFinishLaunchingWithOptions:] + 162
20 UIKit 0x35db3821 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772
21 UIKit 0x35dadb65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272
22 UIKit 0x35d827d7 -[UIApplication handleEvent:withNewEvent:] + 1114
23 UIKit 0x35d82215 -[UIApplication sendEvent:] + 44
24 UIKit 0x35d81c53 _UIApplicationHandleEvent + 5090
25 GraphicsServices 0x35a56e77 PurpleEventCallback + 666
26 CoreFoundation 0x30881a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
27 CoreFoundation 0x3088383f __CFRunLoopDoSource1 + 166
28 CoreFoundation 0x3088460d __CFRunLoopRun + 520
29 CoreFoundation 0x30814ec3 CFRunLoopRunSpecific + 230
30 CoreFoundation 0x30814dcb CFRunLoopRunInMode + 58
31 UIKit 0x35dacd49 -[UIApplication _run] + 372
32 UIKit 0x35daa807 UIApplicationMain + 670
33 ShowroomLocator 0x0000278b main + 70
34 ShowroomLocator 0x00002740 start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.2 (8H7)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
(gdb)
After adding SearchDisplayController with _tableview1 my application started crashing.
I have two tableview in same controller class. Pleas suggest something to handle this...
Edited with multiple tableview coding:
- (void)viewDidLoad {
appDelegate = (ShowroomLocatorAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *items = [[NSArray alloc] initWithObjects:
#"Sydney Airport (SYD), Mascot NSW 2020, Australia",
#"Sydney NSW, Australia'",
#"Smithfield NSW 2164, Australia",
#"Smithfield SA 5114, Australia",
#"Smithfield QLD 4878, Australia",
nil];
self.allItems = items;
[items release];
self._tableView1.scrollEnabled = YES;
_tableView1.hidden = YES;
_tableView.hidden = YES;
[self._tableView reloadData];
self._tableView.rowHeight = 80.0;
[ self.view addSubview:_tableView] ;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView1.delegate = self;
_tableView1.dataSource = self;
}
- (void)viewWillAppear:(BOOL)animated
{
[self._tableView reloadData];
[self._tableView1 reloadData]; }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if(tableView ==_tableView && tableView ==_tableView1 )
{
return 1;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(tableView ==_tableView )
{
if(section == 0)
return [NSString stringWithFormat:NSLocalizedString(#"ShowRooms[%d]", #"Showroom format"), [appDelegate.markers count]];
}
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableview numberOfRowsInSection:(NSInteger)section {
if(tableview ==_tableView )
{
return [appDelegate.markers count];
}
if(tableview ==_tableView1 )
{ NSInteger rows = 0;
if ([_tableView1
isEqual:self.searchDisplayController.searchResultsTableView]){
rows = [self.searchResults count];
}
else{
rows = [self.allItems count];
}
return rows;
}
}
In my _tableview web-service data get fill and _tableview1 array data with address get fill.....
The above error is coming on adding _tableview1.....
I suspect, in viewWillAppear, you did a reloadData specifying self rather than self.tableView.

iphone table view scroll aborts - unrecognized selector

I know there have been a ton of questions about the same thing, but so far I haven't been able to apply any solutions to my problem. And I still haven't figured out how to use Instruments.
I'm taking a basic tutorial for an iPhone app and just trying to tweak it slightly (I am new to Objective C). I want it to read from a plist with an array of dicts instead of an array of strings. The table initially displays the data correctly. However whenever I scroll the table up (and off the screen), I am getting Unrecognized Selector exceptions. Just populating employees with NSStrings works fine. I am lost.
Relevant portions of the ViewController:
#interface RootViewController : UITableViewController {
NSMutableArray *employees_;
}
#property (nonatomic, retain) NSMutableArray *employees;
#end
and
#implementation RootViewController
#synthesize employees=employees_;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:#"Employees" ofType:#"plist"];
NSMutableArray *empArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
employees_ = [empArray valueForKey:#"name"];
[empArray release];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [self.employees objectAtIndex:indexPath.row];//this is where it errors
return cell;
}
- (void)dealloc
{
[employees_ release];
[super dealloc];
}
#end
and plist:
array
dict
key name /key
string Employee One /string
key id /key
string T1234 /string
/dict
dict
key name /key
string Employee Two /string
key id /key
string T5678 /string
/dict
/array
Error that I received:
2011-10-18 20:02:44.313 MyApp[65148:bc03] -[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x689a050
2011-10-18 20:02:44.316 MyApp[65148:bc03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x689a050'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f16313 objc_exception_throw + 44
2 CoreFoundation 0x00dc40bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d33966 ___forwarding___ + 966
4 CoreFoundation 0x00d33522 _CF_forwarding_prep_0 + 50
5 MyApp 0x00002a96 -[RootViewController tableView:cellForRowAtIndexPath:] + 326
6 UIKit 0x00089b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
7 UIKit 0x0007f4cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
8 UIKit 0x000948cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
9 UIKit 0x0008c90c -[UITableView layoutSubviews] + 242
10 QuartzCore 0x016aca5a -[CALayer layoutSublayers] + 181
11 QuartzCore 0x016aeddc CALayerLayoutIfNeeded + 220
12 QuartzCore 0x016540b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
13 QuartzCore 0x01655294 _ZN2CA11Transaction6commitEv + 292
14 QuartzCore 0x0165546d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
15 CoreFoundation 0x00da389b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
16 CoreFoundation 0x00d386e7 __CFRunLoopDoObservers + 295
17 CoreFoundation 0x00d011d7 __CFRunLoopRun + 1575
18 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
20 GraphicsServices 0x00ffa1c4 GSEventRunModal + 217
21 GraphicsServices 0x00ffa289 GSEventRun + 115
22 UIKit 0x00022c93 UIApplicationMain + 1160
23 MyApp 0x00002249 main + 121
24 MyApp 0x000021c5 start + 53
)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
(gdb)
There are two potential problems:
You need to make sure the call to employees_ = [empArray valueForKey:#"name"] is actually returning a NSArray
Once one is ruled out, and assuming you are not using ARC, your employees_ ivar is getting released before the table view gets a chance to configure itself. Try
employees_ = [[empArray valueForKey:#"name"] retain];
And then release employees_ in your viewDidUnload & dealloc methods.
Hard to tell it from the stack as it does say your ivar is a NSCFString but it could be just because it is referencing an invalid/garbage memory address. Based on your plist description though, the likely cause on on point #1.
-[NSCFString objectAtIndex:]: unrecognized selector
This means you tried to send the selector (i.e. call the method) objectAtIndex: on an instance of class NSCFString (which is the same as NSString). ("Next Step / Core Foundation String")
You can't do that.
Since you only are calling objectAtIndex: in one place in your above code, it's easy to see where the problem is. (Besides which in your debugger you should be able to see what line it happens on.) You're calling [self.employees objectAtIndex:...]. Obviously you expect self.employees to be an array, but it is a string instead. I don't really know about plist processing, so figuring out why employees got a string and how to make it get an array instead is up to you.

SIGABRT received due to this code... Why?

I am trying to implement a tab bar controller, navigation controller and tableview into an application I'm working on but I am getting a SIGABRT error each time I try to run it and I don't know why and it is rather puzzling me. Below is the code that the console is referencing to (I believe):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSString *cellValue = [listOfCoffees objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
...and below is the console:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x6a17c00'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dca5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f1e313 objc_exception_throw + 44
2 CoreFoundation 0x00dcc0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d3b966 ___forwarding___ + 966
4 CoreFoundation 0x00d3b522 _CF_forwarding_prep_0 + 50
5 UIKit 0x00091b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
6 UIKit 0x000874cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
7 UIKit 0x0009c8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
8 UIKit 0x0009490c -[UITableView layoutSubviews] + 242
9 QuartzCore 0x016b4a5a -[CALayer layoutSublayers] + 181
10 QuartzCore 0x016b6ddc CALayerLayoutIfNeeded + 220
11 QuartzCore 0x0165c0b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
12 QuartzCore 0x0165d294 _ZN2CA11Transaction6commitEv + 292
13 QuartzCore 0x0165d46d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
14 CoreFoundation 0x00dab89b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
15 CoreFoundation 0x00d406e7 __CFRunLoopDoObservers + 295
16 CoreFoundation 0x00d091d7 __CFRunLoopRun + 1575
17 CoreFoundation 0x00d08840 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00d08761 CFRunLoopRunInMode + 97
19 GraphicsServices 0x010021c4 GSEventRunModal + 217
20 GraphicsServices 0x01002289 GSEventRun + 115
21 UIKit 0x0002ac93 UIApplicationMain + 1160
22 Affogato 0x00002259 main + 121
23 Affogato 0x000021d5 start + 53
24 ??? 0x00000001 0x0 + 1
)
terminate called throwing an exception
Any help would be greatly appreciated.
I'm quite sure the actual problem is somewhere else in the code, my guess would be you are using some string variable (possibly selectedCoffee ?) in place of the tableView's delegate.
The error is in the tableview delegate/datasource. CellForRowAtIndexPath is called by the tableview to query it's UITableViewCell object. Check your delegate/datasource connection.
Set a breakpoint and look where the app crash. Then we could help more.

Iphone application crashes when I scroll the UITableView

I am using this code for table delegates
my application crashes when I scroll table till last row i.e langTable
if sometime application not crashes then I am not able to scroll the table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(#"Test 0");
if (tableView==langTable) {
NSLog(#"Test 0 complete lang table %d",[langArray count]);
return [langArray count];
}else if (tableView==gameTypeTable) {
NSLog(#"Test 0 complete gametype %d",[gameTypeArray count]);
return [gameTypeArray count];
}
NSLog(#"Test 0 complete 0");
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSString *cellValue;
if (tableView==langTable) {
NSLog(#"1Test 1...%d-%#",indexPath.row,[[langArray objectAtIndex:indexPath.row] objectForKey:#"lang_caption"]);
cellValue = [[langArray objectAtIndex:indexPath.row] objectForKey:#"lang_caption"];
}else if (tableView==gameTypeTable) {
NSLog(#"2Test 1...%d-%#",indexPath.row,[[gameTypeArray objectAtIndex:indexPath.row] objectForKey:#"caption"]);
cellValue = [[gameTypeArray objectAtIndex:indexPath.row] objectForKey:#"caption"];
}else {
NSLog(#"3Test 1...%d-kuch.ni.hai",indexPath.row);
cellValue = #"";
}
cell.text = cellValue;
NSLog(#"Text 1 Complete");
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"select");
if (tableView==langTable) {
NSLog(#"langTable1");
functionality.gameLang = indexPath.row;
NSLog(#"langTable2");
}else if (tableView==gameTypeTable) {
NSLog(#"gameTypeTable1");
functionality.gameType = indexPath.row;
NSLog(#"gameTypeTable2");
}
}
Log comes on the crash time are
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x026a7919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x027f55de objc_exception_throw + 47
2 CoreFoundation 0x0269d465 -[__NSArrayM objectAtIndex:] + 261
3 SensoryStimulation 0x00006fe5 -[Functionality onPageChange:] + 829
4 SensoryStimulation 0x000029cc -[SensoryStimulationViewController scrollViewDidEndDecelerating:] + 126
5 UIKit 0x0030b0ad -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 322
6 UIKit 0x00315fbb -[UIScrollView(Static) _smoothScroll:] + 3999
7 UIKit 0x003337b8 -[UITableView(_UITableViewPrivate) _smoothScroll:] + 75
8 UIKit 0x00301e88 ScrollerHeartbeatCallback + 129
9 GraphicsServices 0x02e9556d HeartbeatTimerCallback + 35
10 CoreFoundation 0x02688d43 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
11 CoreFoundation 0x0268a384 __CFRunLoopDoTimer + 1364
12 CoreFoundation 0x025e6d09 __CFRunLoopRun + 1817
13 CoreFoundation 0x025e6280 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x025e61a1 CFRunLoopRunInMode + 97
15 GraphicsServices 0x02e922c8 GSEventRunModal + 217
16 GraphicsServices 0x02e9238d GSEventRun + 115
17 UIKit 0x002d5b58 UIApplicationMain + 1160
18 SensoryStimulation 0x000027aa main + 84
19 SensoryStimulation 0x0000272a start + 54
)
terminate called after throwing an instance of 'NSException'
Whats wrong with code
Amit Battan
I found the wrong thing
Actually I am also using a UIScrollView in my app, when Table scroll ends then scrollViewDidEndDecelerating method calls which I have use for the UIScrollView.
As UITableView has super class UIScrolView
Amit Battan

iPhone: Core Data saving error

I am getting the following error when trying to save an object into my core data model:
2010-09-01 22:07:50.569 Score Card[26566:207] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1262.60.3/UITableView.m:904
2010-09-01 22:07:50.570 Score Card[26566:207] Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. Invalid update: invalid number of sections. The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted). with userInfo (null)
Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
_Unwind_Resume called from function -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] in image CoreData.
2010-09-01 22:07:50.572 Score Card[26566:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x02661b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x027b140e objc_exception_throw + 47
2 CoreFoundation 0x0261a238 +[NSException raise:format:arguments:] + 136
3 Foundation 0x000bae37 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x0033a9a6 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 7806
5 UIKit 0x0032a75b -[UITableView insertSections:withRowAnimation:] + 56
6 Score Card 0x00003918 -[History controller:didChangeSection:atIndex:forChangeType:] + 133
7 CoreData 0x0246db81 -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 2177
8 Foundation 0x0002a0e1 _nsnote_callback + 145
9 CoreFoundation 0x02639f29 __CFXNotificationPost_old + 745
10 CoreFoundation 0x025b926a _CFXNotificationPostNotification + 186
11 Foundation 0x0001fc8a -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
12 CoreData 0x023a8879 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 89
13 CoreData 0x02418193 -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 259
14 CoreData 0x0238b208 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 1352
15 CoreData 0x023c4e55 -[NSManagedObjectContext save:] + 149
16 Score Card 0x000053ad -[TimeRun saveAction] + 65
17 Score Card 0x00004116 -[TimeRun countDown] + 326
18 Foundation 0x000561c9 __NSFireTimer + 125
19 CoreFoundation 0x02642f73 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
20 CoreFoundation 0x026445b4 __CFRunLoopDoTimer + 1364
21 CoreFoundation 0x025a0dd9 __CFRunLoopRun + 1817
22 CoreFoundation 0x025a0350 CFRunLoopRunSpecific + 208
23 CoreFoundation 0x025a0271 CFRunLoopRunInMode + 97
24 GraphicsServices 0x02f4000c GSEventRunModal + 217
25 GraphicsServices 0x02f400d1 GSEventRun + 115
26 UIKit 0x002ceaf2 UIApplicationMain + 1160
27 Score Card 0x00002998 main + 102
28 Score Card 0x00002929 start + 53
)
terminate called after throwing an instance of 'NSException
I am just not sure how to fix the issue. I am not inserting any sections, so I am at a loss here. Ideas?
EDIT:
Does it have to do with how I am fetching my results? It seems I am using a key for section name, but I don't want sections:
- (NSFetchedResultsController *)fetchedResultsController {
if (fetchedResultsController != nil) {
return fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Mission" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Create the sort descriptors array.
NSSortDescriptor *startDescriptor = [[NSSortDescriptor alloc] initWithKey:#"title" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:startDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Create and initialize the fetch results controller.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:#"title" cacheName:#"Root"];
self.fetchedResultsController = aFetchedResultsController;
self.fetchedResultsController.delegate = self;
// Memory management.
[aFetchedResultsController release];
[fetchRequest release];
[startDescriptor release];
[sortDescriptors release];
return fetchedResultsController;
}//end
If you still want a section name.The following code works:
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex
forChangeType:(NSFetchedResultsChangeType)type{
switch(type)
{
case NSFetchedResultsChangeInsert:
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
default:
break;
}
}
This tells you your problem:
Invalid update: invalid number of
sections. The number of sections
contained in the table view after the
update (1) must be equal to the number
of sections contained in the table
view before the update (1), plus or
minus the number of sections inserted
or deleted (1 inserted, 0 deleted).
After the update, you are returning the incorrect number of sections from 'numberOfSectionsInTableView:`. Most likely, something in update changes the sections but you keep returning the old section number count.
Setting sectionNameKeyPath: to nil has fixed my issue.
they say you delete the app in your simulator then "Clean all build targets" then rebuild and run again. Hope this helps
I based my answer on: 'NSInternalInconsistencyException'