首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AddressBook API的问题- NSInternalInconsistencyException

AddressBook API的问题- NSInternalInconsistencyException
EN

Stack Overflow用户
提问于 2010-08-10 14:51:36
回答 1查看 400关注 0票数 0

我的情况如下:

我们正在创建一个应用程序(除其他外)显示Exchange中公用文件夹中的数据。我们希望我们的iPhone应用程序像iPhone那样显示联系人(就像苹果的AddressBook应用程序一样),因此我们正在使用AddressBook API。但是,我们不打算在iPhone本身上保存任何显示的联系人,它只用于在Exchange的公用文件夹中显示联系人。

当我们将要显示一个联系人记录时,我们使用'pushViewController‘方法来显示一个'ABUnknownPersonViewController’。在代码中,我们使用ABRecordRef ()方法创建ABPersonCreate对象。它的一部分工作良好,我看到名称和其他细节显示在标题(旁边的图片占位符)。但是,一旦我添加了要显示在UITableViewCell布局中的任何细节(比如电话、地址等)它没有出现。更糟糕的是,一旦我第二次加载ABPersonViewController,这个应用程序就会崩溃,而'setDisplayedPerson:‘方法正在被调用。注意:它第一次加载很好,但是它没有显示应该在UITableViewCells中显示的数据。

我收到以下错误消息:

代码语言:javascript
复制
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'

下面是我代码的一部分:

代码语言:javascript
复制
 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);
 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-11 08:37:53

我找到了解决这个问题的办法。显然,在视图控制器中创建person (ABRecordRef)对象并不是一种好方法。相反,在加载ABUnknownViewController之前创建person。还可以调用setDisplayedPerson:在加载ABUnknownViewController之前。这样就可以正确初始化行和节,不再会有任何不一致的异常。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3450259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档