2つの異なるカスタムセルを使用してUITableViewControllerを作成しようとしています。私は多くの投稿を見てきましたが、特にこれは、2つの異なる再利用識別子の使用を示唆しています。私はそれをやっています、そして私はまだ最初のカスタムセルのサイズを取得しているようです。2番目のセルのラベルなどは表示されませんが、サイズは同じようです。データの表示方法は異なりますが、セルサイズは同じです。
問題がどこにあるのかわからないので、必要以上のコードが含まれている可能性がありますので、あらかじめお詫び申し上げます。
TableViewControllerのコードは次のとおりです。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
//set equal to the information in the array
return [jsonDataArray count];
}
- (void) addHeaderAndFooter
{
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
v.backgroundColor = [UIColor clearColor];
//[self.tableView setTableHeaderView:v];
[self.tableView setTableFooterView:v];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SCellIdentifier = @"SCell";
static NSString *PCellIdentifier = @"PCell";
NSLog(@"%@",indexPath);
NSLog(@"JSONDATAARRAY: %i", jsonDataArray.count);
NSDictionary *jsoninfo = [jsonDataArray objectAtIndex:indexPath.row];
if (indexPath.row == 0)
{
OBPromoCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:PCellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[OBPromoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PCellIdentifier];
}
//get required keys from dictionary and assign to vairables
NSString *title = [jsoninfo objectForKey:@"title"];
NSString *subtitle = [jsoninfo objectForKey:@"subtitle"];
NSURL *imageURL = [NSURL URLWithString:[jsoninfo objectForKey:@"image_URL"]];
//download the images. This will most lilely need to be made asynchronous.... I don't think it is now.
NSData *imgData = [NSData dataWithContentsOfURL:imageURL];
UIImage *img = [[UIImage alloc] initWithData:imgData];
//fill in text to cells
cell.CustomCellTopLabel.text = title;
cell.CustomCellBottomLabel.text = subtitle;
cell.CellImageView.image = img;
return cell;
}
else
{
OBStandardCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:SCellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[OBStandardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SCellIdentifier];
}
//get required keys from dictionary and assign to vairables
NSString *title = [jsoninfo objectForKey:@"title"];
NSString *subtitle = [jsoninfo objectForKey:@"subtitle"];
NSURL *imageURL = [NSURL URLWithString:[jsoninfo objectForKey:@"series_image_URL"]];
//download the images. This will most lilely need to be made asynchronous.... I don't think it is now.
NSData *imgData = [NSData dataWithContentsOfURL:imageURL];
UIImage *img = [[UIImage alloc] initWithData:imgData];
//fill in text to cells
cell.CustomCellTopLabel.text = title;
cell.CustomCellBottomLabel.text = subtitle;
cell.CellImageView.image = img;
return cell;
}
}
これが私のストーリーボードが参照用にどのように設定されているかの画像です。繰り返しますが、それらには異なる再利用識別子があります。
助けてくれてありがとう!!!