UITableView不显示通讯簿

时间:2012-01-20 17:23:21

标签: 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和地址簿的新手:)

1 个答案:

答案 0 :(得分:3)

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

在将数字和姓氏添加到数组后(或[myTableView reloadData];

)中尝试添加viewWillAppear: