Я использую раскадровку, и мой пользовательский UICollectionViewCell не появляется. Я играл с ним в течение нескольких часов и искал множество различных решений, но никто не работал. Просто для пояснения, данные существуют, и появляется UICollectionView, но ячейка не является. Вот мой код. Мы ценим любые предложения!Пользовательский UICollectionViewCell не загружается
- (NSInteger)collectionView:(UICollectionView *)mutualFriendsView numberOfItemsInSection:(NSInteger)section {
return [self.resultsDictionary count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)mutualFriendsView
cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"PCRRequesterMutualFriendsCollectionViewCell";
PCRRequesterMutualFriendsCollectionViewCell *cell = [self.mutualFriendsView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
NSArray *idArray = [self.resultsDictionary objectForKey:@"id"];
NSArray *nameArray = [self.resultsDictionary objectForKey:@"name"];
cell.profileName.text = [nameArray objectAtIndex:indexPath.row];
cell.backgroundColor = [UIColor redColor];
return cell;
}
- (void)collectionView:(UICollectionView *)mutualFriendsView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cell #%d was selected", indexPath.row);
}
- (BOOL)shouldAutorotate {
[mutualFriendsView.collectionViewLayout invalidateLayout];
BOOL retVal = YES;
return retVal;
}
EDIT Вот мой viewDidLoad
self.mutualFriendsView.dataSource = self;
self.mutualFriendsView.delegate = self;
self.mutualFriendsView.pagingEnabled = YES;
// [self.mutualFriendsView registerClass:[PCRMutualFriendsCollectionViewCell class] forCellWithReuseIdentifier:@"PCRMutualFriendsCollectionViewCell"];
Редактировать Я думаю, что я понял, проблема. Я не думаю, что словарь заполняется после завершения блока завершения. Любые предложения по сохранению значения словаря из блока, который будет использоваться за его пределами?
__block NSMutableDictionary *mutualFriends = nil;
__block NSNumber *total;
NSString *u = [NSString stringWithFormat:@"%@",self.details[@"Requester"][@"profile"][@"facebookId"]];
/* make the API call */
[FBRequestConnection startWithGraphPath:(@"/%@", u)
parameters:params
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
/* handle the result */
if (!error){
NSLog(@"RESULT OF FB %@", result);
if (result == nil){
NSLog(@"No shared friends");
} else {
total = result[@"context"][@"mutual_friends"][@"summary"][@"total_count"];
NSLog(@"TOTAL FRIENDS %@", total);
for(int i=0;i<[result[@"context"][@"mutual_friends"][@"data"] count];i++)
{
mutualFriends = result[@"context"][@"mutual_friends"][@"data"][i];
NSLog(@"FRIENDDATA %@", mutualFriends);
}
}
} else {
NSLog(@"ERROR %@", error);
}
}];
self.resultsDictionary = mutualFriends;
self.number = total;
NSLog(@"NUMBER %@", self.number);
NSLog(@"RESULTS DICTIONARY %@", self.resultsDictionary);
NSString *friends = [NSString stringWithFormat:@"You have %@ friends in common including:", self.number];
Вызывается ли метод cellForItemAtIndexPath вообще? –
только что проверил - его нет. Вы не знаете, почему это может быть? – StePWa
Должен быть метод, который поставляет количество секций в коллекции. Если это возвращает 0, то метод числа или элементов не будет вызываться. Кроме того, когда заносится в список resultsDictionary? Если после viewDidLoad вам, вероятно, понадобится вызвать collectionView.reloadData() после заполнения списка resultsDictionary. –