と呼ばれるfriendsListUITableView
からアイテムを読み取るがあります。NSMutableArray
ここでこの配列を初期化します。
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
self.title = TA(@"Find Friends", @"");
self.navigationItem.rightBarButtonItem = [self createRightNavBarButton];
self.navigationItem.leftBarButtonItem = [self createLeftNavBarButton];
friendsList = [[NSMutableArray alloc]init];
}
return self;
}
カウントがゼロより大きい場合に返すdatasource
メソッドを設定しました。numberOfRows
friendslist.count
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (friendsList.count) {
return friendsList.count;
}
else{
return 0;
}
}
呼び出している別のメソッドで配列を埋めた後[tableView reloadData]
、datasource
メソッドが再度呼び出されて配列内のオブジェクトの数が読み取られるようにします。
- (void)loadContactsFromSource:(ListSource)source
{
if (friendsList) {
[friendsList removeAllObjects];
}
switch (source) {
case LS_Facebook:
break;
case LS_Twitter:
break;
case LS_Contacts:{
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil, nil);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted) {
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(
kCFAllocatorDefault,
CFArrayGetCount(allPeople),
allPeople
);
CFArraySortValues(
peopleMutable,
CFRangeMake(0, CFArrayGetCount(peopleMutable)),
(CFComparatorFunction) ABPersonComparePeopleByName,
(void*) ABPersonGetSortOrdering()
);
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
for ( int i = 0; i < nPeople; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(peopleMutable, i);
[self copyContactToArray:ref];
}
[tableFriends reloadData];
}
else{
[PopupHandler popupDialogWithTitle:T(@"Error", @"")
message:T(@"Access denied", @"")
delegate:nil];
}
});
break;
}
default:
break;
}
}
cellForRow メソッドは次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSDictionary *currentPerson = [friendsList objectAtIndex:indexPath.row];
cell = [self fillCell:cell withUserInfo:currentPerson];
return cell;
}
問題は、このテーブルが空白のままになった後、配列の項目が表示されないことです。指でテーブルに触れると、テーブルがリフレッシュされたかのように、アイテムがすぐに表示されます。これを引き起こしている可能性のあるアイデアはありますか?
XCode 5.0.1 から構築された iOS 7 を搭載した iPhone 5 でこれをテストしています。