我知道你不能在一个UITableView
个单元中混合静态和动态单元类型,但我想不出更好的方式来描述我的问题.
我有几个具有固定内容的预定细胞,我也有未知数量的细胞,它们位于中间.所以我想让我的桌子看起来像这样:
Fixed
Fixed
Fixed
Dynamic
Dynamic
Dynamic
Dynamic
Dynamic
Fixed
Fixed
那么,你到底建议我如何在我的cellForRowAtIndexPath
方法中实现这一点呢?
谢谢
我知道你不能在一个UITableView
个单元中混合静态和动态单元类型,但我想不出更好的方式来描述我的问题.
我有几个具有固定内容的预定细胞,我也有未知数量的细胞,它们位于中间.所以我想让我的桌子看起来像这样:
Fixed
Fixed
Fixed
Dynamic
Dynamic
Dynamic
Dynamic
Dynamic
Fixed
Fixed
那么,你到底建议我如何在我的cellForRowAtIndexPath
方法中实现这一点呢?
谢谢
正如你所说,你不能混合静态和动态细胞.但是,您可以将内容分解为与每个组对应的不同数据array.然后将表拆分为不同的部分,并从CellForRowatineXpath:中的正确数组加载数据.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"CELLID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
switch (indexPath.section) {
case 0:{
cell.textLabel.text = self.arrayOfStaticThings1[indexPath.row];
}break;
case 1:{
cell.textLabel.text = self.arrayOfDynamicThings[indexPath.row];
}break;
case 2:{
cell.textLabel.text = self.arrayOfStaticThings2[indexPath.row];
}break;
default:
break;
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:{
return self.arrayOfStaticThings1.count;
}break;
case 1:{
return self.arrayOfDynamicThings.count;
}break;
case 2:{
return self.arrayOfStaticThings2.count;
}break;
default:
return 0;
break;
}
}