Я пытаюсь показать представление коллекции, у которого есть пользовательская коллекция. Мой массив кажется пустым, и я не могу понять, почему. Вот мой код. Я все пробовал!AFNetworking & CollectionView
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"opportunityCell";
OpportunityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
// Opportunity *opportunity = [self.opportunitiesArray objectAtIndex:indexPath.row];
for (Opportunity *opportunity in self.opportunitiesArray) {
NSString *opportunityBanner = opportunity.imageBanner;
NSURL *imageURl = [NSURL URLWithString:opportunityBanner];
NSData *imageData = [NSData dataWithContentsOfURL:imageURl];
RKCardView *cardView = [[RKCardView alloc]initWithFrame:CGRectMake(0, 0, cell.cellView.bounds.size.width, cell.cellView.bounds.size.height)];
cardView.coverImageView.image = [[UIImage alloc]initWithData:imageData];
cardView.titleLabel.text = @"";
cardView.profileImageView.image = [[UIImage alloc]initWithData:imageData];
UITextView *descriptionView = [[UITextView alloc]initWithFrame:CGRectMake(15, 180, cell.cellView.bounds.size.width - 15, cell.cellView.bounds.size.height/3)];
descriptionView.text = opportunity.opportunityName;
descriptionView.editable = NO;
descriptionView.font = [UIFont fontWithName:@"Avenir" size:18];
descriptionView.contentMode = UIControlContentVerticalAlignmentCenter;
UITextView *timeView = [[UITextView alloc]initWithFrame:CGRectMake(15, 180 + cell.cellView.bounds.size.height, cell.cellView.bounds.size.width - 5, cell.cellView.bounds.size.height/3)];
timeView.text = opportunity.endDateTime;
timeView.editable = NO;
timeView.font = [UIFont fontWithName:@"Avenir" size:14];
cardView.layer.cornerRadius = 10;
cell.cellView.layer.cornerRadius = 10;
[cardView addSubview:descriptionView];
[cardView addSubview:timeView];
[cell.cellView addSubview:cardView];
[descriptionView setTextAlignment:NSTextAlignmentCenter];
}
[self.collectionView reloadData];
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]initWithBaseURL:[NSURL URLWithString:BaseURLString]];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
self.opportunitiesArray = [[NSMutableArray alloc]init];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:@"opportunities/" parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
Opportunity * opportunity = [[Opportunity alloc]init];
if (responseObject[@"opportunities"]) {
[KVNProgress showSuccess];
NSDictionary *dataDict = responseObject[@"data"];
opportunity.opportunityID = dataDict[@"id"];
opportunity.opportunityDescription = dataDict [@"description"];
// opportunity.isDonatable = dataDict[@"donatable"];
opportunity.endDateTime = dataDict[@"end_datetime"];
opportunity.opportunityName = dataDict[@"name"];
opportunity.opportunityType = dataDict[@"opp_type"];
opportunity.organizationID = dataDict[@"organization_id"];
// opportunity.isPrivate = dataDict[@"donatable"];
opportunity.startDateTime = dataDict[@"start_datetime"];
// opportunity.isAttendable = dataDict[@"attendable"];
opportunity.imagecard = dataDict[@"image_card_organization"];
opportunity.imageBanner = dataDict[@"image_banner"];
[self.opportunitiesArray addObject:opportunity];
}
[self.collectionView reloadData];
NSLog(@"JSON: %@", responseObject);
}
failure:
^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
Я также использую структуру под названием RKCardView для создания моей ячейки. Должен ли я создать пользовательскую ячейку вместо использования сторонней структуры?
вы можете показать мне, где вы устанавливаете вид коллекции делегат и источник данных для себя код? Или просто подтвердите, если вы установили его в раскадровке или xib – Ted
У вас есть это решение? – Mrunal