사용자 지정 UITableViewCells가있는 UITableView가 있습니다. 사용자 지정 UITableViewCells는 NSDictionary를 사용하여 레이블과 이미지를 채 웁니다. 내 문제는, NSArray 각 셀 (NSDictionaries) 내부 정보를 서버에서 반환했습니다. 모든 셀은 UITableViewCell과 동일한 서브 클래스이지만 모든 셀이 다른 배열을 사용해야합니다.사용자 지정 셀이있는 UITableView
다음//I use this method to create the cell, and build it using the NSDictionary passed to it
+ (CategoryCell *)generateCategoryCellWithInfo:(NSDictionary *)dict;
{
CategoryCell *cell;
NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"CategoryCell" owner:self options:nil];
cell = [xib objectAtIndex:0];
if (dict != nil)
{
//build the cell
cell.videoTitle.font = [UIFont fontWithName:@"FuturaStd-CondensedBold" size:17.0f];
cell.videoTitle.text = [dict objectForKey:@"title"];
dispatch_async(dispatch_get_global_queue(0, 0), ^(void){
NSData *fullImageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[dict objectForKey:@"fullImage"]]];
if (!fullImageData)
{
return;
}
else
{
dispatch_async(dispatch_get_main_queue(), ^(void){
[cell.contentButton setImage:[UIImage imageWithData:fullImageData] forState:UIControlStateNormal];
});
}
});
cell.numberOfViewsLabel.text = [NSString stringWithFormat:@"%@ views", [dict objectForKey:@"views"]];
}
else
{
//set placeholders
cell.numberOfViewsLabel.text = @"1200 people viewed this";
cell.numberOfLikesLabel.text = @"20 people liked this";
[cell.contentButton setImage:[UIImage imageNamed:@"[email protected]"] forState:UIControlStateNormal];
cell.videoTitle.text = @"A Baby Dances in its Car Seat or Something";
}
return cell;
}
는 세포가 지금
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CategoryCellIdentifier = @"categoryCell";
CategoryCell *cell = (CategoryCell *)[tableView dequeueReusableCellWithIdentifier:CategoryCellIdentifier];
if (!cell)
{
cell = [CategoryCell generateCategoryCellWithInfo:[itemsArray objectAtIndex:0]];
cell.delegate = self;
}
return cell;
}
을 만들어 난 그냥있는 NSArray itemsArray에 처음있는 NSDictionary를 사용하고,하지만 각 셀이 전달 갖고 싶어 : 여기에 몇 가지 코드입니다 itemsArray 내의 다른 NSDictionary. 누군가 나를 도울 수 있습니까? 당신이 당신의 테이블에 0 섹션을 사용하는 경우
완벽하게 작동합니다! 도와 주셔서 감사합니다. –
다행, 천만에. – anneblue