"Drink Mixer" Example Head First iPhone & iPad Development - iphone

i'm kinda new to Objective-C so i have been learning with the Head First iPhone & iPad Development book. In this book, at the Chapter 4-5 you suppose to design an app for a bartender, that basically is a table view of a list of drinks with the details list (it suppose to have the ingredients and directions for the drink selected). The data comes from two property lists, one has a list of strings with the names of the drinks, and the other is a Dictionary that has the name, directions and ingredients of the drinks.
I have followed the tutorial and the app crashes, re-checked it and still crashes. I'm using an Xcode Version of 4.0.1 and MAC OS X 10.6.8.
Here is the exception, i hope that you guys can check out what happens at this simple application.
2012-07-19 21:43:39.757 DrinkMixer[846:207] -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x4b31220
2012-07-19 21:43:39.761 DrinkMixer[846:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x4b31220'
*** 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 DrinkMixer 0x00002495 -[RootViewController tableView:cellForRowAtIndexPath:] + 325
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 UIKit 0x000169c9 -[UIApplication _reportAppLaunchFinished] + 39
15 UIKit 0x00016e83 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
16 UIKit 0x00021617 -[UIApplication handleEvent:withNewEvent:] + 1533
17 UIKit 0x00019abf -[UIApplication sendEvent:] + 71
18 UIKit 0x0001ef2e _UIApplicationHandleEvent + 7576
19 GraphicsServices 0x00ffb992 PurpleEventCallback + 1550
20 CoreFoundation 0x00da3944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
21 CoreFoundation 0x00d03cf7 __CFRunLoopDoSource1 + 215
22 CoreFoundation 0x00d00f83 __CFRunLoopRun + 979
23 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
24 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
25 UIKit 0x000167d2 -[UIApplication _run] + 623
26 UIKit 0x00022c93 UIApplicationMain + 1160
27 DrinkMixer 0x00001c89 main + 121
28 DrinkMixer 0x00001c05 start + 53
)
terminate called after throwing an instance of 'NSException'
sharedlibrary apply-load-rules all
(gdb)
And here is exactly when the app crashes, at the objectForKey:#"name"
- (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];
}
cell.textLabel.text = [[self.drinks objectAtIndex:indexPath.row] objectForKey:#"name"];
return cell;
}

the clue in the first line of the error is that you have initialized the contents of self.drinks at the index that corresponds to indexPath.row to be an NSString. when that objectAtIndex: is retrieved, it is then passed the message objectForKey: as though it is an NSArray.
look at the code where you've initialized self.drinks and make certain you've made it an appropriate array containing appropriate contents. in your case, it would be an array of NSDictionary* for objectForKey: to work).

Debug your code and check drinks is an array of NSDictonary.

Related

Error during Navigation point

I have created one navigation based application. In that first view show me the list of the drinks and in second view it show me the Details of the Drinks.
All seems ok but while i am navigatting the view at (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath Method, It will show me the error like
terminate called after throwing an instance of 'NSException'
at line
[self.navigationController pushViewController:drinkDetailViewController animated:YES];
Plese help me, why it happens like that ?
My code for the method is as follow:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *drinkDetailViewController = [[DrinkDetailViewController alloc] initWithNibName:#"DrinkDetailViewController" bundle:nil];
//UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:drinkDetailViewController];
//[self presentModalViewController:drinkDetailViewController animated:YES];
//[self dismissModalViewControllerAnimated:YES];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:drinkDetailViewController animated:YES];
[drinkDetailViewController release];
}
While i click on row, it shows me that exception message.
This is project log:
2011-08-10 10:18:10.559 DrinkMixer_Shreyash[694:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "DrinkDetailViewController" nib but the view outlet was not set.'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f16313 objc_exception_throw + 44
2 CoreFoundation 0x00d7aef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x00d7ae6a +[NSException raise:format:] + 58
4 UIKit 0x000c6709 -[UIViewController _loadViewFromNibNamed:bundle:] + 295
5 UIKit 0x000c4134 -[UIViewController loadView] + 120
6 UIKit 0x000c400e -[UIViewController view] + 56
7 UIKit 0x000c2482 -[UIViewController contentScrollView] + 42
8 UIKit 0x000d2f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
9 UIKit 0x000d1555 -[UINavigationController _layoutViewController:] + 43
10 UIKit 0x000d27aa -[UINavigationController _startTransition:fromViewController:toViewController:] + 326
11 UIKit 0x000cd32a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
12 UIKit 0x000d4562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932
13 UIKit 0x000cd1c4 -[UINavigationController pushViewController:animated:] + 62
14 DrinkMixer_Shreyash 0x000029bf -[RootViewController tableView:didSelectRowAtIndexPath:] + 191
15 UIKit 0x0008bb68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
16 UIKit 0x00081b05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
17 Foundation 0x0079b79e __NSFireDelayedPerform + 441
18 CoreFoundation 0x00da38c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
19 CoreFoundation 0x00da4e74 __CFRunLoopDoTimer + 1220
20 CoreFoundation 0x00d012c9 __CFRunLoopRun + 1817
21 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
22 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
23 GraphicsServices 0x00ffa1c4 GSEventRunModal + 217
24 GraphicsServices 0x00ffa289 GSEventRun + 115
25 UIKit 0x00022c93 UIApplicationMain + 1160
26 DrinkMixer_Shreyash 0x00002089 main + 121
27 DrinkMixer_Shreyash 0x00002005 start + 53
28 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
sharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)
Please help me regarding it. . .
iDroid Exploer , in your drinkDetailViewController class you have to connect the view variable to the view element of the Xib file. It has to be done via interface builder.
This is the crash regarding that your IBOutlet for View in DrinkDetailViewController is not set in XIB file. Please set Your View in XIB and then try to run the app. This is done using Interface builder..
Happy Coding...

UITable cellForRowAtIndexPath

New in iOS, here is Question:
I am using xcode 4.0.2 iso-4.3.2.
Here I have a table and I am creating one mutable array like
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello"nil];
and sending that value to.Table delegate method like
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
here value is coming but once I am sending dynamically value to the mainarray like
mainarray=[[NSMutableArray alloc]initWithObjects:[dataarray valueForKey:#"first_name"],nil]; or
[mainarray addobject:[dataarray valueForKey:#"first_name"]]
and sending that mainarray value to cell.textlabel.text then my program is terminating and sending this error message.
2011-05-11 10:29:10.346 picture:vide[742:207] -[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x4e85200
2011-05-11 10:29:10.348 picture:vide[742:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x4e85200'
*** Call stack at first throw:
(
0 CoreFoundation 0x00ddb5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f2f313 objc_exception_throw + 44
2 CoreFoundation 0x00ddd0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d4c966 ___forwarding___ + 966
4 CoreFoundation 0x00d4c522 _CF_forwarding_prep_0 + 50
5 UIKit 0x003ecafc -[UILabel setText:] + 72
6 picture:vide 0x000050c9 -[VideoChatController1 tableView:cellForRowAtIndexPath:] + 376
7 UIKit 0x00340b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x003364cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x0034b8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x0034390c -[UITableView layoutSubviews] + 242
11 QuartzCore 0x01d7ba5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01d7dddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01d230b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01d24294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01d2446d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00dbc89b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d516e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00d1a1d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00d19840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00d19761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x017321c4 GSEventRunModal + 217
22 GraphicsServices 0x01732289 GSEventRun + 115
23 UIKit 0x002d9c93 UIApplicationMain + 1160
24 picture:vide 0x00002910 main + 102
25 picture:vide 0x000028a1 start + 53
)
Please, help.
Here you are getting this terminating log because
dataArray is an NSArray you can't call [dataarray valueForKey:#"first_name"] this
because this unreconised for NSArray
rether than this you may use some thing like this
[[dataarray objectAtIndex:index] valueForKey:#"first_name"]
[__NSArrayI isEqualToString:]: is the issue. You are using the isEqualToString: for an array somewhere. Check that. Its a method of NSString
Initialization of array was wrong.
Following line
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello"nil];
should be corrected as
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello" , nil];
Please note the new comma between #"Hello" and nil

iPhone - Multithreading in Tableview - feasible approach?

I have been tracking a nasty bug recently of which I knew it was occurring due to my multithreaded approach (I add the crashreport at the end).
In my App I load a UITableView and fill it with data I store using Coredata. This data in turn I retrieve from a webservice, thus it might take some time, depending on my connection.
Anyway, I have managed to track it down a little and I know the issue is because an array is empty though I thought it shouldn't be. Then, when
numberOfRowsInSection:(NSInteger)section
is called the program crashes - but only sometimes!!!
I was wondering how to debug this properly and my approach was to call
reloadData
on the tableView after the view finishes loading. But appearantly
- (void)viewDidLoad
but of course this didn't help. Is the correct way here to create another thread and have it check repeatadly whether the data is ready and prepared? Any suggestions/opinions?
2011-01-19 21:50:49.605 myApp[2017:307] *** Terminating app due to uncaught exception
'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x314d0987 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x319a149d objc_exception_throw + 24
2 CoreFoundation 0x31462795 -[__NSArrayM objectAtIndex:] + 184
3 myApp 0x000092f7 -[MyTableViewController tableView:numberOfRowsInSection:] + 106
4 UIKit 0x33902bcf -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1338
5 UIKit 0x33903529 -[UITableViewRowData(UITableViewRowDataPrivate) _ensureSectionOffsetIsValidForSection:] + 120
6 UIKit 0x33902645 -[UITableViewRowData numberOfRows] + 96
7 UIKit 0x3390207b -[UITableView noteNumberOfRowsChanged] + 82
8 UIKit 0x33901bff -[UITableView reloadData] + 582
9 UIKit 0x33904a0b -[UITableView _reloadDataIfNeeded] + 50
10 UIKit 0x33904e63 -[UITableView layoutSubviews] + 18
11 UIKit 0x338b10cf -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 26
12 CoreFoundation 0x3146ebbf -[NSObject(NSObject) performSelector:withObject:] + 22
13 QuartzCore 0x30a6c685 -[CALayer layoutSublayers] + 120
14 QuartzCore 0x30a6c43d CALayerLayoutIfNeeded + 184
15 QuartzCore 0x30a6656d _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 212
16 QuartzCore 0x30a66383 _ZN2CA11Transaction6commitEv + 190
17 QuartzCore 0x30a70e4f _ZN2CA11Transaction5flushEv + 46
18 QuartzCore 0x30a6db75 +[CATransaction flush] + 24
19 UIKit 0x338e803f -[UIApplication _reportAppLaunchFinished] + 30
20 UIKit 0x338d6317 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 462
21 UIKit 0x338a248b -[UIApplication handleEvent:withNewEvent:] + 1114
22 UIKit 0x338a1ec9 -[UIApplication sendEvent:] + 44
23 UIKit 0x338a1907 _UIApplicationHandleEvent + 5090
24 GraphicsServices 0x35d66f03 PurpleEventCallback + 666
25 CoreFoundation 0x314656ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
26 CoreFoundation 0x314656c3 __CFRunLoopDoSource1 + 166
27 CoreFoundation 0x31457f7d __CFRunLoopRun + 520
28 CoreFoundation 0x31457c87 CFRunLoopRunSpecific + 230
29 CoreFoundation 0x31457b8f CFRunLoopRunInMode + 58
30 UIKit 0x338d5309 -[UIApplication _run] + 380
31 UIKit 0x338d2e93 UIApplicationMain + 670
32 myApp 0x000029bf main + 70
33 myApp 0x00002974 start + 40
)
terminate called after throwing an instance of 'NSException'
numberOfRows looks like:
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSLog(#"number of rows in section");
if (section == mySection) {
return [[articleArrays objectAtIndex:section] count];
} else {
return 0;
}
}
From what you describe here your process that performs the download, or more precisely an event callback should be the only place calling reload data. calling it after adding new data to the table dataSet.
returning a 0 in numberOfRowsInSection does not cause a crash but if you are trying to get a nested array when the count is 0, this will crash. Post your numberOfRowsInSection method for us to gawk at.
EDIT:
Sounds/Looks like background thread is mutating the array while its trying to do an object count.
user210504 is right in saying that synchronising the array is likely stop this.
Typically you would sync writes and therefore preventing numberOfRowsInSection from counting if your background thread is mutating it. eg:
-(void)downloadFinished{
NSMutableArray * array = [[NSArray alloc] init];//t
id * obj;//obj is your row data object.
#synchronized(ar)
{
[array addObject:obj];//ar is your dataSet
}
[array release];
}
One thing that you can do is to encapsulate accesses to the Mutable Array in #synchronized block. This way you will be sure that you are not accessing the datastructure half way through. And then I also agree with what Luke just mentioned.

unrecognized selector sent to instance. Method being called for random objects

Ok, so this has me completely stumped just like the guy here with the exact problem.
I have a UITableView with some rows in a view controller which supports autorotation and sometimes, if i rotate the phone, i get "EXC_BAD_ACCESS" and sometimes i get SIGABRT with a stack trace like:
2010-11-19 16:51:05.634 [2306:307] -[CABasicAnimation numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x58207d0
2010-11-19 16:51:05.688 [2306:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CABasicAnimation numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x58207d0'
*** Call stack at first throw:
(
0 CoreFoundation 0x344aaed3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x33975811 objc_exception_throw + 24
2 CoreFoundation 0x344ac683 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x344541d9 ___forwarding___ + 508
4 CoreFoundation 0x34453f90 _CF_forwarding_prep_0 + 48
5 UIKit 0x31b20717 -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 66
6 UIKit 0x31b20677 -[UITableViewRowData invalidateAllSections] + 50
7 UIKit 0x31b2048d -[UITableView(_UITableViewPrivate) _updateRowData] + 64
8 UIKit 0x31b22941 -[UITableView(_UITableViewPrivate) _ensureRowDataIsLoaded] + 24
9 UIKit 0x31b22909 -[UITableView numberOfSections] + 16
10 UIKit 0x31bd114f -[UISearchDisplayController _updateNoSearchResultsMessageVisiblity] + 54
11 UIKit 0x31cfbef7 -[UISearchDisplayController windowWillAnimateRotation:] + 478
12 Foundation 0x3325d6b3 _nsnote_callback + 142
13 CoreFoundation 0x34431713 __CFXNotificationPost_old + 402
14 CoreFoundation 0x344313b3 _CFXNotificationPostNotification + 118
15 Foundation 0x3324cdb7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
16 UIKit 0x31b5dbb7 -[UIWindow _setRotatableClient:toOrientation:duration:force:] + 3114
17 UIKit 0x31b64013 -[UIWindow _setRotatableViewOrientation:duration:force:] + 50
18 UIKit 0x31b39a0f -[UIWindow _updateToInterfaceOrientation:duration:force:] + 74
19 UIKit 0x31b39be9 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 112
20 UIKit 0x31b39b15 -[UIWindow _handleDeviceOrientationChange:] + 88
21 Foundation 0x3325d6b3 _nsnote_callback + 142
22 CoreFoundation 0x34431713 __CFXNotificationPost_old + 402
23 CoreFoundation 0x344313b3 _CFXNotificationPostNotification + 118
24 Foundation 0x3324cdb7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
25 UIKit 0x31b0d0ed -[UIDevice setOrientation:animated:] + 144
26 UIKit 0x31b2a51b -[UIApplication handleEvent:withNewEvent:] + 2738
27 UIKit 0x31b29901 -[UIApplication sendEvent:] + 44
28 UIKit 0x31b29337 _UIApplicationHandleEvent + 5110
29 GraphicsServices 0x3026c04b PurpleEventCallback + 666
30 CoreFoundation 0x3443fce3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
31 CoreFoundation 0x3443fca7 __CFRunLoopDoSource1 + 166
32 CoreFoundation 0x3443256d __CFRunLoopRun + 520
33 CoreFoundation 0x34432277 CFRunLoopRunSpecific + 230
34 CoreFoundation 0x3443217f CFRunLoopRunInMode + 58
35 GraphicsServices 0x3026b5f3 GSEventRunModal + 114
36 GraphicsServices 0x3026b69f GSEventRun + 62
37 UIKit 0x31ad0123 -[UIApplication _run] + 402
38 UIKit 0x31ace12f UIApplicationMain + 670
39 App 0x0000285f main + 70
40 App 0x00002814 start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
In this case it is CABasicAnimation on which numberOfSectionsInTableView is being called but sometimes there are class names like NSMachPort which i have never heard of. Also, the method being called numberOfSectionsInTableView remains the same with the class names changing to always give a doesNotRecognizeSelector exception.
Also this problem only happens when i try to rotate the device. Whenever i get a stack trace like above, there are all system functions which makes it difficult to debug.
Really need some expert advice on this. Please read the forum mentioned above to be clear about the issue.
Whoa! I thought i knew NSZombies enough but i was wrong!
I enabled NSZombies which led me to:
*** -[ContactsViewController numberOfSectionsInTableView:]: message sent to deallocated instance 0x88dafa0
Doing "po 0x88dafa0" wont work because that object's memory was already freed.
Some more Googling led me to this where the author describes how to find freed/deallocated objects. We just have to set MallocStackLoggingNoCompact to 1 in the Variables to be set in the environment along with NSZombieEnabled.
The output i got with the info malloc-history 0xf270740 command had a line:
-[VoicePlayController actionSheet:clickedButtonAtIndex:] at /Users/Documents/Xcode Projects/Classes/VoicePlayController.m:454
The code on that line is:
contactsViewController = [[ContactsViewController alloc] initWithNibName:#"ContactsViewController" bundle:nil];
I moved the [contactsViewController release]; line to dealloc method instead of immediately after [self.navigationController presentModalViewController:contactsViewController animated:YES]; and the problem is gone!
Start with enabling NSZombies. What it sounds like is you are over-releasing an object.

iOS Application Terminates After Exception Thrown in UITableViewDataSource Method

Having meticulously followed the examples and instructions in the Table View Programming Guide for iOS about the proper order in which UITableView delegate and data source methods are called, I thought I had a good idea of how to implement the “handshake” shown in Figure 7-1 and the list that follows, but apparently not.
Here's the code I'm using…
- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath *) indexPath {
NSLog(#"Removing %# row %d.", [dataModel objectAtIndex: indexPath.row], indexPath.row);
[tableView deleteRowsAtIndexPaths: [NSArray arrayWithObjects: indexPath, nil] withRowAnimation: UITableViewRowAnimationFade];
[dataModel removeObjectAtIndex: indexPath.row];
}
tableView is the UITableView
dataModel is an NSArray instance that holds the objects represented by the UITableViewCells from the tableView.
…and the error I'm getting…
2010-08-27 21:53:17.971 SportWatch[1299:307] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1262.58/UITableView.m:920
2010-08-27 21:53:17.992 SportWatch[1299:307] *** 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 (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x35411ed3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x311f0811 objc_exception_throw + 24
2 CoreFoundation 0x35411d15 +[NSException raise:format:arguments:] + 68
3 Foundation 0x332b932f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
4 UIKit 0x338dcda1 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 4524
5 UIKit 0x338d586d -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 204
6 UIKit 0x338d5775 -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 20
7 SportWatch 0x000060e7 -[MainViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 670
8 UIKit 0x338d3c3f -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 58
9 UIKit 0x33984071 -[UITableViewCell(UITableViewCellInternal) deleteConfirmationControlWasClicked:] + 28
10 CoreFoundation 0x353b9719 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
11 UIKit 0x33831d59 -[UIApplication sendAction:to:from:forEvent:] + 84
12 UIKit 0x33831cf9 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
13 UIKit 0x33831ccb -[UIControl sendAction:to:forEvent:] + 38
14 UIKit 0x33831a1d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
15 UIKit 0x3383206b -[UIControl touchesEnded:withEvent:] + 342
16 UIKit 0x338309f5 -[UIWindow _sendTouchesForEvent:] + 368
17 UIKit 0x3383036f -[UIWindow sendEvent:] + 262
18 UIKit 0x3382ae13 -[UIApplication sendEvent:] + 298
19 UIKit 0x3382a74b _UIApplicationHandleEvent + 5110
20 GraphicsServices 0x3171a04b PurpleEventCallback + 666
21 CoreFoundation 0x353a6ce3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
22 CoreFoundation 0x353a6ca7 __CFRunLoopDoSource1 + 166
23 CoreFoundation 0x3539956d __CFRunLoopRun + 520
24 CoreFoundation 0x35399277 CFRunLoopRunSpecific + 230
25 CoreFoundation 0x3539917f CFRunLoopRunInMode + 58
26 GraphicsServices 0x317195f3 GSEventRunModal + 114
27 GraphicsServices 0x3171969f GSEventRun + 62
28 UIKit 0x337d148b -[UIApplication _run] + 402
29 UIKit 0x337cf69f UIApplicationMain + 670
30 SportWatch 0x00002b23 main + 70
31 SportWatch 0x00002ad8 start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
kill
Current language: auto; currently objective-c
quit
remove the object from the data set before deleting the row.