我正在尝试使用两个不同的自定义单元格制作 UITableViewController。我看过很多帖子,最值得注意的是this,它建议使用两个不同的重用标识符。我正在这样做,我似乎仍然得到了第一个自定义单元格的大小。它没有显示第二个单元格的标签等,但大小似乎相同。数据显示不同,但单元格大小相同。
由于我不知道问题出在哪里,我可能会包含不必要的代码,所以我提前道歉。
这是我的 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;
}
}
这是我的故事板设置方式的图像以供参考。同样,它们确实有不同的重用标识符:
感谢您的任何帮助!!!