[英]How to implement UITableView With Static and Dynamic Cells — IOS
我创建了一个UITableView,它完全由四个不同的组组成。 每个部分/组具有不同数量的行。 我已经为底部的三个组静态添加了必要数量的行和文本字段。 但是,我不知道顶部/组将需要多少行。 我将顶级组设置为在.xib中只有一个单元格,但是每次视图加载时,我都必须检查我需要多少个单元格,然后将必要的行数动态添加到顶部。
我环顾了StackOverflow,看到人们在讨论insertRowsAtIndexPaths方法,但是我无法使其工作。
[settingsPageTableView beginUpdates];
[settingsPageTableView insertRowsAtIndexPaths:tempArray withRowAnimation:UITableViewRowAnimationAutomatic];
[settingsPageTableView endUpdates];
我是否需要在insertRowsAtIndexPaths方法中放入一些特定的代码? 我已经通过了NSMutableArray:
NSIndexPath *indexPath0 = [NSIndexPath indexPathForRow:1 inSection:0];
NSMutableArray *tempArray=[NSMutableArray array];
[tempArray addObject:indexPath0];
如果有人知道如何在一个UITableView中组合静态和动态单元格,将不胜感激! 对于任何熟悉iPhone常规设置中的蓝牙页面的人,这正是我想要做的。 它具有可变数量的设备显示,以及在顶部包含UISwitch的静态单元格。 有谁知道如何做到这一点?
谢谢一群!
我认为您应该动态地完成所有操作,只是因为您在蓝牙页面上描述的单元始终存在,并不意味着它是一个静态单元,而是总是动态创建的。
所以这是我刚想出的解决方法。 我知道,对于UITable View的顶部,我永远不会需要超过7个单元格。 这样,我就可以在.xib文件中静态设置这7个了。 从那里,我只能使用此命令显示所需的具体号码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch(section) {
case 0:
//Do a bunch of checking here on how many i actually need. Then, I will just return the required amount. As long as it is less than the number of cells I have statically placed in my .xib, everything works good.
return 4;
case 1:
return 3;
case 2:
return 1;
case 3:
return 2;
case 4:
return 3;
default:
return 0;
}
//Every case but the first always needs the same amount of cells, so those are no problem.
}
最佳和最简单的方法:
1)将容器视图放置在动态TableView的标题中2)将静态TableView分配给此容器,然后取消选中“滚动启用”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.