UITableView混合静态和动态单元?

编程入门 行业动态 更新时间:2024-10-27 08:33:23
本文介绍了UITableView混合静态和动态单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道你不能在一个 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混合静态和动态单元?

本文发布于:2023-08-05 21:40:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   单元   动态   UITableView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!