我想通过使用故事板在一个表视图中添加2个或更多不同的自定义单元格.
我知道如何在没有故事板的情况下添加不同的单元格.我总是这样做:
我知道如何在没有故事板的情况下添加不同的单元格.我总是这样做:
static Nsstring *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//pictureCell = [[DetailPictureCell alloc]init];//(DetailPictureCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
pictureCell.header = true;
[pictureCell setHeader];
if (cell == nil) {
if ([indexPath row] == 0) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HeaderAngebotViewCell" owner:self options:nil];
NSLog(@"New Header Cell");
}
if([indexPath row] ==1){
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"productCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
现在我的问题:我怎么能用故事板做这个?
添加一个自定义单元格是可能的.但我不能添加两个不同的单元格.你能帮我吗?
解决方法
在表视图的属性检查器中,选择“动态原型”及其下面的选择原型单元格的数量.给每个单元格一个不同的标识符,当cellForRowAtIndexPath中的单元格出列时,请使用基于indexPath的适当的标识符.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Nsstring *identifier;
if (indexPath.row == 0) {
identifier = @"OneCellId";
} else if (indexPath.row == 1) {
identifier = @"OtherCellId";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//configure cell...
}