ios - UITableView不显示通讯簿

标签 ios tableview addressbook

我想我没有掌握地址簿和UITableView的句柄,或者也许只是使其变得比实际更简单。

这是我的.h文件:

@interface Contacts : UITableViewController <ABPeoplePickerNavigationControllerDelegate> {

NSMutableArray *menuArray;
NSString *firstName;
NSString *lastName;
UIButton *addcontact;
}

@property (nonatomic, retain) NSMutableArray *menuArray;
@property (nonatomic, strong) UIButton *addcontact;
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;

-(void)showPeoplePickerController;
@end

和我的.m文件:
 -(IBAction)addcontact:(id)sender {

ABPeoplePickerNavigationController *peoplePicker=[[ABPeoplePickerNavigationController alloc] init];

[peoplePicker setPeoplePickerDelegate:self];



[self presentModalViewController:peoplePicker animated:YES];  }
- (void)viewDidLoad
{
menuArray = [[NSMutableArray alloc] init];

[super viewDidLoad];

} 

- (BOOL)peoplePickerNavigationController:

(ABPeoplePickerNavigationController *)peoplePicker

  shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    [menuArray addObject:firstName]; 
    lastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
    [menuArray addObject:lastName];



[self dismissModalViewControllerAnimated:YES];
return NO;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return [menuArray count];
}


- (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];
}

NSString *cellValue = [menuArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

return cell;

}

我希望有人可以帮助我,我是UITableViews和Addressbook的新手:)

最佳答案

出于性能目的(更不用说动画目的),只要数据源发生更改,UITableView不会自动更新自身。

在将名字和姓氏添加到数组后(或在[myTableView reloadData];中),尝试添加viewWillAppear:

关于ios - UITableView不显示通讯簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8945347/

相关文章:

java - 具有更多功能的通讯录程序

c++ - CoGetClassObject 返回错误

iphone - iOS 开发 : NSDateFormatter problem

ios - UICollectionViewCell 翻转动画

ios - 按星期几对字符串数组进行排序

ios - 将 Interface Builder 中的 UIBarButtonItem 添加到导航的 UIViewController?

python - pyqt - 更改 TableView 中的行~单元格颜色

iphone - 排序数组不会删除我想要的

ios - 如何在 Swift 中固定到 TableView 的顶部?

ios - 未经许可或询问访问 iOS 联系人列表 - 隐私问题