Removing Objects from UITableView - iphone

So I've seen similar topics but I don't quite understand why I am crashing still....
I am reading entries into an array called "entries." After a while I want to add new entries and then delete the old ones.
So I'm essentially adding stuff to 'entries" and then wanting to delete some old entries. I then run the below method and dies out when it starts editing the view. The error is posted below the code block.
Thanks for the help!
-(void) removeOldEntries: (int) numOfEntries
{
NSMutableArray *deleteIndexPaths = [[NSMutableArray alloc] init] ;
// Remove the first number of entries in the table view. This number is specified by the numOfEntries
for (int i = numOfEntries - 1; i >= 0; i = i -1 )
{
[entries removeObjectAtIndex:i];
}
// Build deleteIndexPaths
for (int i = numOfEntries - 1; i >= 0; i = i - 1)
{
// Add objects to our index pathes array (of things we need to delete) and then remove the objects from feeds array
[deleteIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
// Start the editing of the TableView
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
// End the editing of the table view
[deleteIndexPaths removeAllObjects];
[deleteIndexPaths release];
}
Error message:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UITableView.m:976
2011-12-27 22:43:04.490 v1.0[999:6003] *** 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 (8) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x00e3dbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f925c2 objc_exception_throw + 47
2 CoreFoundation 0x00df6628 +[NSException raise:format:arguments:] + 136
3 Foundation 0x000d847b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x0035aa0f -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8424
5 UIKit 0x0034a433 -[UITableView endUpdates] + 42
6 v1.0 0x000050e6 -[NewsTableViewController removeOldArticles:] + 408
7 v1.0 0x00004d16 -[NewsTableViewController pullAndParseData] + 696
8 CoreFoundation 0x00dae67d __invoking___ + 29
9 CoreFoundation 0x00dae551 -[NSInvocation invoke] + 145
10 Foundation 0x000ff555 -[NSInvocationOperation main] + 51
11 Foundation 0x0006dbd2 -[__NSOperationInternal start] + 747
12 Foundation 0x0006d826 ____startOperations_block_invoke_2 + 106
13 libSystem.B.dylib 0x96653a24 _dispatch_call_block_and_release + 16
14 libSystem.B.dylib 0x96645cf2 _dispatch_worker_thread2 + 228
15 libSystem.B.dylib 0x96645781 _pthread_wqthread + 390
16 libSystem.B.dylib 0x966455c6 start_wqthread + 30
)
terminate called after throwing an instance of 'NSException'

You are making this needlessly complicated. There is some inconsistency in your deletion which is why there is an error. Make sure in
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//return for section 0
return [entries count];
}
And change your removeOldEntries: to
-(void) removeOldEntries: (int) numOfEntries
{
[entries removeObjectsInRange:NSMakeRange(0, numOfEntries-1)];
[self.tableView reloadData];
}

Use [_tableView reloadData]. This will simplify your life.
By the way, the exception you are getting is indicating that your array is not containing what you think it should. Trying NSLogging your array.

Related

Swift delete row with animation

Unfortunately, I have to ask this question again, because I have not found a solution yet.
At the moment I can delete it without animation, but now I want to delete it WITH animation.
My app get an error with this code:
/*************** TABLE VIEW DELETE LEBENSMITTEL ***************/
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == .Delete) {
let LM_ITEM = lebensmittel[indexPath.row]
managedObjectContext!.deleteObject(lebensmittel[indexPath.row])
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
self.DatenAbrufen()
}
}
2015-08-28 09:27:27.475 [32099:346567] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3347.44.2/UITableView.m:1623
2015-08-28 09:27:27.483 [32099:346567] *** 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 (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(
0 CoreFoundation 0x00000001091cdc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010b126bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001091cdaca +[NSException raise:format:arguments:] + 106
3 Foundation 0x00000001098ac98f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000109f37c13 -[UITableView _endCellAnimationsWithContext:] + 12678
5 UIKit 0x0000000119d2937b -[UITableViewAccessibility deleteRowsAtIndexPaths:withRowAnimation:] + 48
6 App Name 0x00000001087ca640 _TFC12App_Name26AlteLebensmittelController9tableViewfS0_FTCSo11UITableView18commitEditingStyleOSC27UITableViewCellEditingStyle17forRowAtIndexPathCSo11NSIndexPath_T_ + 3360
7 App Name 0x00000001087ca887 _TToFC12App_Name26AlteLebensmittelController9tableViewfS0_FTCSo11UITableView18commitEditingStyleOSC27UITableViewCellEditingStyle17forRowAtIndexPathCSo11NSIndexPath_T_ + 87
8 UIKit 0x0000000109f5d1e6 -[UITableView animateDeletionOfRowWithCell:] + 132
9 UIKit 0x0000000109f3c3bd __52-[UITableView _swipeActionButtonsForRowAtIndexPath:]_block_invoke + 72
10 UIKit 0x0000000109e5bd62 -[UIApplication sendAction:to:from:forEvent:] + 75
11 UIKit 0x0000000109f6d50a -[UIControl _sendActionsForEvents:withEvent:] + 467
12 UIKit 0x0000000109f6c8d9 -[UIControl touchesEnded:withEvent:] + 522
13 UIKit 0x0000000109ea8958 -[UIWindow _sendTouchesForEvent:] + 735
14 UIKit 0x0000000109ea9282 -[UIWindow sendEvent:] + 682
15 UIKit 0x0000000109e6f541 -[UIApplication sendEvent:] + 246
16 UIKit 0x0000000109e7ccdc _UIApplicationHandleEventFromQueueEvent + 18265
17 UIKit 0x0000000109e5759c _UIApplicationHandleEventQueue + 2066
18 CoreFoundation 0x0000000109101431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x00000001090f72fd __CFRunLoopDoSources0 + 269
20 CoreFoundation 0x00000001090f6934 __CFRunLoopRun + 868
21 CoreFoundation 0x00000001090f6366 CFRunLoopRunSpecific + 470
22 GraphicsServices 0x000000010de80a3e GSEventRunModal + 161
23 UIKit 0x0000000109e5a8c0 UIApplicationMain + 1282
24 App Name 0x00000001087ebb67 main + 135
25 libdyld.dylib 0x000000010b868145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The number of rows to show in your tableview is not the same you got in your datasource. Deleting a row with an animation take some time so when the deleting animation end try refreshing the tableview with yourTableview.reloadData() and remove the unused data from your datasource (before the refresh).
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourDataSource[section].count
}
Here an exemple in Objective-C:
- (void)removeRowAtIndex:(NSInteger)aIndex
{
//Set the row to remove from the tableView
NSMutableArray * tRemove = [NSMutableArray array];
NSIndexPath * tIndexPath = [NSIndexPath indexPathForRow:aIndex inSection:0];
[tRemove addObject:tIndexPath];
//Remove the deleted data from the datasource
NSMutableIndexSet * tRemoveIndexSet = [NSMutableIndexSet indexSet];
[tRemoveIndexSet addIndex:aIndex];
[YourDataSource removeObjectsAtIndexes:tRemoveIndexSet];
//Remove the row from tableView
[YourTableView deleteRowsAtIndexPaths:tRemove withRowAnimation:UITableViewRowAnimationLeft];
}
Swift version:
func removeRowAtIndex(aIndex:Int) {
//Set the row to remove from the tableView
var tRemove:Array<NSIndexPath> = Array()
let tIndexPath:NSIndexPath = NSIndexPath(forRow: aIndex, inSection: 0)
tRemove.append(tIndexPath)
//Remove the deleted data from the datasource
var tRemoveIndexSet:NSMutableIndexSet = NSMutableIndexSet()
tRemoveIndexSet.addIndex(aIndex)
YourDataSource.removeAtIndexes(tRemoveIndexSet)
//OR use removeAtIndex()
//YourDataSource.removeAtIndex(aIndex)
//Remove the row from tableView
YourTableView.deleteRowsAtIndexPaths(tRemove, withRowAnimation: .Left)
}
Add this extension if you want to use removeAtIndexes()
extension Array
{
mutating func removeAtIndexes(indexes: NSIndexSet) {
for var i = indexes.lastIndex; i != NSNotFound; i = indexes.indexLessThanIndex(i) {
self.removeAtIndex(i)
}
}
}
Source : removeObjectsAtIndexes for Swift arrays
Hope this can help you :)

Why sometimes my application stops working and gives Program received signal: “SIGABRT” error?

I have four views in my navigational based application. MainView, AddView, ShowView and DetailView. MainView has a NSMutableArray. When i click on button add, then i go to AddView and then i add an object in NSMutable array of MainView. Then i come back and go to ShowView which is a tableView. From MainView i am calling createList function of ShowView like this:
ShowView *show = [[ShowView alloc] init];
[show createList: self.savedObjectsList];
[self.navigationController pushViewController: show animated: YES];
[runListController release];
In ShowView createList looks like this:
- (void) createRunsList: (NSMutableArray *) list{
objList = [list retain];
}
where objList is NSMutableArray in ShowView. every cell of table view creates a DetailView of an object of NSMutbaleArray. Problem is sometimes my applications stop working and i get this error:
2011-10-03 15:35:55.076 RunnoIPhoneApp[2750:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x3399964f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x30b16c5d objc_exception_throw + 24
2 CoreFoundation 0x33904069 -[__NSArrayM objectAtIndex:] + 184
3 RunnoIPhoneApp 0x0000b79f -[PostRunDetailViewController createRunDetail:] + 90
4 RunnoIPhoneApp 0x0000fd2f -[RunListViewController tableView:didSelectRowAtIndexPath:] + 182
5 UIKit 0x3203f51b -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 662
6 UIKit 0x320a30eb -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 130
7 Foundation 0x32ba26d5 __NSFireDelayedPerform + 368
8 CoreFoundation 0x33970a47 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
9 CoreFoundation 0x33972ecb __CFRunLoopDoTimer + 850
10 CoreFoundation 0x33973845 __CFRunLoopRun + 1088
11 CoreFoundation 0x33903ec3 CFRunLoopRunSpecific + 230
12 CoreFoundation 0x33903dcb CFRunLoopRunInMode + 58
13 GraphicsServices 0x3162e41f GSEventRunModal + 114
14 GraphicsServices 0x3162e4cb GSEventRun + 62
15 UIKit 0x32019d69 -[UIApplication _run] + 404
16 UIKit 0x32017807 UIApplicationMain + 670
17 RunnoIPhoneApp 0x00002553 main + 70
18 RunnoIPhoneApp 0x00002508 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.5 (8L1)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Program received signal: “SIGABRT”.
(gdb)
Can anybody tell me why is it happening? DetailView of some first objects works fine but then i get this error. Thanks in advance.
Looking at the stack trace, the exception is thrown in your [PostRunDetailViewController createRunDetail:] method, which is called when you select a row in your RunListViewController's UITableView. You are trying to access an element in the array that is out of bounds.
Put a break point at the start of this method and step through it in the debugger. Work out which array access is causing the exception and then think why the array might not contain the elements that you expect.
Just comment this line
[runListController release];

App terminate due to - uncaught exception 'NSGenericException',

I got the below error while fetching some data from sever. While fetching data, i m displaying an custom alert view with activity indicator. Alert is using main thread while data fetching is done by NSThread. This problem occurs only at some time, not always. I m not able to understand what to do.
* Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection was mutated while being enumerated.(
"",
"",
""
)'
* Call stack at first throw:
(
0 CoreFoundation 0x00f2abe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0107f5c2 objc_exception_throw + 47
2 CoreFoundation 0x00f2a6a9 __NSFastEnumerationMutationHandler + 377
3 UIKit 0x00371b8e -[UIView(Hierarchy) _findFirstSubviewWantingToBecomeFirstResponder] + 189
4 UIKit 0x00366a13 -[UIView(Hierarchy) _promoteDescendantToFirstResponderIfNecessary] + 42
5 MyApplnName 0x00015154 -[SecondViewController getDataFromServer] + 1798
6 Foundation 0x000a1d4c -[NSThread main] + 81
7 Foundation 0x000a1cd8 __NSThread__main__ + 1387
8 libSystem.B.dylib 0x928db7fd _pthread_start + 345
9 libSystem.B.dylib 0x928db682 thread_start + 34
)
terminate called after throwing an instance of 'NSException'
The problem is in part of your code where you enumerate some object, for example, NSMutableArray or NSMutableSet, using for-loop (for (id _obj in object)) and in that loop removing or adding some objects to the same object. It is not possible and causes exception.
You can replace that for-loop with for-loop using index variable:
for (int i=0; i<[object count]; i++)
{
//add or remove objects if you want
}

crash on deleteRowsAtIndexPaths

My application crashes when I'm deleting row from table. Here is my sources where the bug is detected and stack trace. Thanx!
//delete row from database
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"\ncommitEditingStyle");
//delete user from Users table with specified ID
if(editingStyle == UITableViewCellEditingStyleDelete)
{
//Get the object to delete from the array.
[dbManager open: #DB_FILE_NAME];
//get userID from array usersIDList[row] = userID!
NSNumber *usersID = [usersIDList objectAtIndex: [indexPath row]];
[dbManager deleteUserWithID: [usersID intValue] table: #TABLE_USERS fieldName: #"UserID" ];
[dbManager close];
//Delete the object from the table.
[self.tableView deleteRowsAtIndexPaths:
[NSArray arrayWithObject: indexPath]
withRowAnimation: UITableViewRowAnimationFade];
}
}
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
{
NSLog(#"\ndeleteRowsAtIndexPaths");
}
[Session started at 2010-11-15 18:01:23 +0200.]
2010-11-15 18:01:25.052 PhoneBook[12397:207] ******* Accessibility Status Changed: On
2010-11-15 18:01:25.101 PhoneBook[12397:207] ********** Loading AX for: com.yourcompany.PhoneBook ************
2010-11-15 18:01:30.060 PhoneBook[12397:207]
deleteBtnUserClick
2010-11-15 18:01:31.878 PhoneBook[12397:207]
commitEditingStyle
2010-11-15 18:01:31.881 PhoneBook[12397:207] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1262.60.3/UITableView.m:920
2010-11-15 18:01:31.883 PhoneBook[12397: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 (6) must be equal to the number of rows contained in that section before the update (6), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x02510b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0266040e objc_exception_throw + 47
2 CoreFoundation 0x024c9238 +[NSException raise:format:arguments:] + 136
3 Foundation 0x000b8e37 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x00338d37 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8719
5 UIKit 0x00328511 -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 56
6 UIKit 0x0aaca8fc -[UITableViewAccessibility(Accessibility) deleteRowsAtIndexPaths:withRowAnimation:] + 74
7 PhoneBook 0x00003491 -[RootViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 392
8 UIKit 0x0032596d -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
9 UIKit 0x0aacde92 -[UITableViewCellAccessibility(SafeCategory) deleteConfirmationControlWasClicked:] + 62
10 UIKit 0x002be7f8 -[UIApplication sendAction:to:from:forEvent:] + 119
11 UIKit 0x00349de0 -[UIControl sendAction:to:forEvent:] + 67
12 UIKit 0x0034c262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
13 UIKit 0x0034ae0f -[UIControl touchesEnded:withEvent:] + 458
14 UIKit 0x002e23d0 -[UIWindow _sendTouchesForEvent:] + 567
15 UIKit 0x002c3cb4 -[UIApplication sendEvent:] + 447
16 UIKit 0x002c89bf _UIApplicationHandleEvent + 7672
17 GraphicsServices 0x02d6c822 PurpleEventCallback + 1550
18 CoreFoundation 0x024f1ff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
19 CoreFoundation 0x02452807 __CFRunLoopDoSource1 + 215
20 CoreFoundation 0x0244fa93 __CFRunLoopRun + 979
21 CoreFoundation 0x0244f350 CFRunLoopRunSpecific + 208
22 CoreFoundation 0x0244f271 CFRunLoopRunInMode + 97
23 GraphicsServices 0x02d6b00c GSEventRunModal + 217
24 GraphicsServices 0x02d6b0d1 GSEventRun + 115
25 UIKit 0x002ccaf2 UIApplicationMain + 1160
26 PhoneBook 0x000026ec main + 102
27 PhoneBook 0x0000267d start + 53
)
terminate called after throwing an instance of 'NSException'
I've seen this before and it is definitely that you have forgotten to update source of data which fill up table. But that part of code is missing.
The method which caused this is
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ;
}
Yes, the problem was in method numberOfRowsInSection
So, to leave troubles you should:
In function commitEditingStyle delete data from your array, database etc.
Decrement your current row count.
[tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
And all be OK!
Updated Swift 4.2
If you are about to remove last row in section, you should remove entire section instead of row. To do that:
tableView.beginUpdates()
dataArray.remove(at: row)
if tableView.numberOfRows(inSection: section) == 1 {
tableView.deleteSections(IndexSet(integer: section), with: .automatic)
}
else {
tableView.deleteRows(at: indexPath, with: .fade)
}
tableView.endUpdates()
Pretty clear from the error message:
'Invalid update: invalid number of
rows in section 0. The number of rows
contained in an existing section after
the update (6) must be equal to the
number of rows contained in that
section before the update (6), plus or
minus the number of rows inserted or
deleted from that section (0 inserted,
1 deleted).'
The object you are trying to delete doesn't get deleted in your datasource.
If I assume that your UITableViewDataSource uses dbManager too, you have to fix dbManager to actually delete the object.
I got the same error and reason was I delete the last row in the table and
my numberOfSectionsInTableView implementation return rowsArray count which was 0..
changing to minimum of 1 solve the case

AddressBook API woes - NSInternalInconsistencyException

My situation is the following:
We're creating an application that (among other things) shows data from the Public Folders in Exchange. We'd like our iPhone App to display contacts like the iPhone does it by default (like Apple's AddressBook app), therefore we're making use of the AddressBook API. However, we don't intend to save any displayed contacts on the iPhone itself, it will just be used to display contacts in the Public Folders of Exchange.
When we're about to show a contact record, we make use of the 'pushViewController' method to display an 'ABUnknownPersonViewController'. In code we're creating ABRecordRef objects using the ABPersonCreate() method. Part of it works fine, I see the name and other details that are show in the header (next to the picture placeholder). However, once I add any details that are to be shown in a UITableViewCell layout (like phone, address, etc...) it doesn't show up. Worse still, the app crashes once I load a ABPersonViewController for the 2nd time and the 'setDisplayedPerson:' method is being called. Note: the first time it loads just fine, but it doesn't show the data that should be displayed in UITableViewCells.
I receive the following error message:
2010-08-10 16:23:21.624 SharepointApp[5058:207] *** Assertion failure in -[ABPersonTableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1261.5/UITableView.m:904
2010-08-10 16:23:21.627 SharepointApp[5058: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 (0), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x02b05919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02c535de objc_exception_throw + 47
2 CoreFoundation 0x02abe078 +[NSException raise:format:arguments:] + 136
3 Foundation 0x0019a8cf -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x0041863e -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 7808
5 UIKit 0x004086d1 -[UITableView endUpdates] + 42
6 AddressBookUI 0x025a2016 -[ABPersonTableViewDataSource setCurrentTableHeaderView:] + 49
7 AddressBookUI 0x025a194d -[ABPersonTableViewDataSource updateTableHeaderView] + 928
8 AddressBookUI 0x025a2276 -[ABPersonTableViewDataSource setPersonModelController:] + 441
9 AddressBookUI 0x025ef9f0 -[ABPersonViewControllerHelper setDisplayedPeople:] + 307
10 AddressBookUI 0x025efbe5 -[ABPersonViewControllerHelper _updateDisplayedPeople] + 198
11 SharepointApp 0x0006866f -[WSPublicContactDetailViewController retrievePersonDataCompleted:] + 654
12 Foundation 0x0011ee9a __NSThreadPerformPerform + 251
13 CoreFoundation 0x02ae6d7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
14 CoreFoundation 0x02a452cb __CFRunLoopDoSources0 + 571
15 CoreFoundation 0x02a447c6 __CFRunLoopRun + 470
16 CoreFoundation 0x02a44280 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x02a441a1 CFRunLoopRunInMode + 97
18 GraphicsServices 0x0307b2c8 GSEventRunModal + 217
19 GraphicsServices 0x0307b38d GSEventRun + 115
20 UIKit 0x003adb58 UIApplicationMain + 1160
21 SharepointApp 0x00002878 main + 102
22 SharepointApp 0x000027e6 start + 54
23 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Here's part of my the code:
ABRecordRef person = ABPersonCreate();
if (person) {
ABRecordSetValue(person, kABPersonLastNameProperty, #"Schreurs", NULL);
ABRecordSetValue(person, kABPersonFirstNameProperty, #"Wolfgang", NULL);
ABRecordSetValue(person, kABPersonOrganizationProperty, #"Webstate", NULL);
ABMultiValueRef phone = ABMultiValueCreateMutable(kABStringPropertyType);
if (phone) {
ABMultiValueAddValueAndLabel(phone, #"06 123 432 23", kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phone, NULL);
CFRelease(phone);
}
[self setUnknownPersonViewDelegate:self];
[self setDisplayedPerson:person];
CFRelease(person);
}
I found the solution to this problem. Apparently it's not a good approach to create the person (ABRecordRef) object inside the view controller. Instead create the person before loading the ABUnknownViewController. Also call [setDisplayedPerson:] before loading the ABUnknownViewController. This way the rows and sections get correctly initialized, there won't be any inconsistency exceptions anymore.