我想通过使用故事板在一个表视图中添加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... }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。