我知道你不能在一个 UITableView 中混合静态和动态细胞类型,但我想不出更好的方式来描述我的问题。
I know you cannot mix Static and Dynamic cell types in a single UITableView but I couldn't think of a better way to describe my issue.
我有几个具有固定内容的预定单元格,我还有未知数量的具有动态内容的单元格位于中间。所以我希望我的桌子看起来像这样:
I have several predetermined cells with fixed content, I also have an unknown number of cells with dynamic content which sits in the middle. So I want to my table to look something like this:
Fixed Fixed Fixed Dynamic Dynamic Dynamic Dynamic Dynamic Fixed Fixed那你怎么建议我在我的 cellForRowAtIndexPath 方法中接近这个?
So how exactly do you recommend I approach this in my cellForRowAtIndexPath method?
谢谢。
推荐答案如你所说,你不能混合静态和动态细胞。但是,您可以做的是将内容分解为与每个组对应的不同数据阵列。然后将表拆分为差异部分并从cellForRowAtIndexPath中的正确数组加载数据:。
As you stated you can't mix static and dynamic cells. However, what you can do is break up the content into different data arrays that correspond to each group. Then break the table up into difference sections and load the data from the correct array in cellForRowAtIndexPath:.
- (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; } }更多推荐
UITableView混合静态和动态单元?
发布评论