在表视图中组合静态和原型内容 [英] Combine static and prototype content in a table view

查看:96
本文介绍了在表视图中组合静态和原型内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用storyboard将静态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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆