[英]Two UITableViewCell with different identifier and different height in storyboard
I have two type of cells that I'll be using my UITableView, so I created two prototype cell with different identifier. 我有两种类型的单元格将要使用UITableView,因此我创建了两个具有不同标识符的原型单元格。 I manuelly changed the size but when I compile and run, the two cells have same size.
我手动更改了大小,但是在编译和运行时,两个单元格的大小相同。
Is there any way to do it through storyboard and without checking every single time 有没有办法通过情节提要而无需每次都检查
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
I will have around a good 100 cells at least. 我至少会有大约100个单元。
UPDATE : in my case I have a tableview with 3 sections, the first one is small, the second and the third one are bigger. 更新 :就我而言,我有一个包含3个部分的表视图,第一个部分较小,第二个和第三个较大。
I think your best option is to use that -tableView:heightForRowAtIndexPath: delegate method you listed and return the height you would like. 我认为最好的选择是使用列出的-tableView:heightForRowAtIndexPath:委托方法并返回所需的高度。
You could assign tags to each prototype and use an if/else if conditional. 您可以为每个原型分配标签,并在条件条件下使用if / else。
Or if you have a subclassed UITableViewCell for each prototype you could do something like 或者,如果每个原型都有一个子类UITableViewCell,则可以执行以下操作
...
id cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[CustomCell1 class]]) {
// return aNumber;
} else if ([cell isKindOfClass:[CustomCell2 class]]) {
// return aNumber;
} else {
return aNumber;
}
...
If you know that the sections if what determines the height of the cell, then you can implement it like this: 如果您知道这些部分决定了单元的高度,那么您可以像这样实现它:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath*)indexPath {
CGFloat result;
if (indexPath.section == 0) {
result = 160;
} else {
result = 80;
}
return result;
}
Depending on the heights that you need of course. 当然,取决于您所需的高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.