在表格视图中结合静态和原型内容 [英] Combine static and prototype content in a table view
本文介绍了在表格视图中结合静态和原型内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用故事板将静态 tableview 单元格(静态内容)与动态 tableview 单元格(原型内容)结合起来?
Is there a way to combine static tableview cells (static content) with dynamic tableview cells (prototype content) using storyboard?
推荐答案
我建议您将表格视为动态表格,但在顶部包含您一直想要的单元格.在 Storyboard 中,放置一个 UITableViewController
并让它使用动态表.根据需要向表中添加任意数量的 UITableViewCell
原型.比如说,一个代表静态单元格,一个代表可变单元格.
I suggest you treat your table as dynamic, but include the cells you always want at the top. In the Storyboard, place a UITableViewController
and have it use a dynamic table. Add as many UITableViewCell
prototypes to the table as you need. Say, one each for your static cells, and one to represent the variable cells.
在你的 UITableViewDataSource
类中:
#define NUMBER_OF_STATIC_CELLS 3
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dynamicModel count] + NUMBER_OF_STATIC_CELLS;
}
然后,然后
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row < NUMBER_OF_STATIC_CELLS) {
// dequeue and configure my static cell for indexPath.row
NSString *cellIdentifier = ... // id for one of my static cells
} else {
// normal dynamic logic here
NSString *cellIdentifier = @"DynamicCellID"
// dequeue and configure for [self.myDynamicModel objectAtIndex:indexPath.row]
}
}
这篇关于在表格视图中结合静态和原型内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文