【问题标题】:How to create Sections in Cell in Table View?如何在表格视图的单元格中创建部分?
【发布时间】:2017-02-22 12:27:24
【问题描述】:

我正在创建 Receipt 视图,为此我正在使用 tableview。我创建了多个单元格来实现此功能。

这是我使用多个单元格的代码:

if indexPath.section == 4    {
    let cell:ProductSummaryTitleCell = self.tblCategorySummary.dequeueReusableCellWithIdentifier("ProductSummaryTitleCell") as! ProductSummaryTitleCell
    //set the data here
    return cell
}

这是我的屏幕截图,我的表格视图中正是我想要的。

[![收据查看][1]][1]

数据结构

(
    {
    Amount = "39.5";
    Numbers = 5;
    Productname = "BLACK PEPPER CHICKEN";
    Upgrade = 0;
    UpgradeCount = 0;
    "product_id" = 53;
},
    {
    Amount = "10.9";
    Numbers = 1;
    Productname = "WHOLE SPRING CHICKEN";
    Upgrade = 0;
    UpgradeCount = 0;
    "product_id" = 60;
})

这是我的类别回复

[
"category_type": mc,
"deleted_date": 0000-00-00 00:00:00,
"created_date": 2015-11-19 21:34:40,
"category_name": chicken,
"company_id": 1,
"category_invoice_name": Chicken,
"Ids": 358,
"updated_by": 2,
"category_icon_image": baa8ae5668029596f6efd9dc00d4c11f.png,
"created_by": 2,
"category_description": chicken,
"update_date": 2016-06-20 22:04:47,
"take_away_price": 0.5,
"branch_id": 1,
"parent_category": 0,
"set_menu": 1,
"pos_id": 6,
"category_status": 1,
"category_image": 6751d0f61304080148b79530d33c5735.png,
"is_deleted": 0,
"category_id": 11
]

我可以进行分类汇总。
但是在产品摘要中你可以看到有部分。

我只使用一个表格视图。
如何为特定单元格创建部分?
我拿了一个产品摘要的单元格。
我只想要此单元格中的部分。
我想根据截图创建产品摘要。

【问题讨论】:

  • 你可能会发现看看这个最近的讨论很有用,它解释了如何在表格视图单元格中嵌套表格视图:stackoverflow.com/questions/17398058/…
  • 你能展示一下你的数据数组是什么样子的吗?
  • @Mr.Bista 我用我想展示的产品的数组结构更新了问题。每个类别都包含这些数据
  • 您确定它是完整的数据信息吗?因为我没有看到任何东西,所以将 Category SummaryProduct summary(Sub Category: Chicken, Fish etc.) 分开
  • @Mr.Bista done.plz 检查这是否足够?

标签: ios swift uitableview


【解决方案1】:

在单个 tableview 中将“Category Summary”显示为 tableview 标题 和“产品摘要”,您可以使用部分和单元格。

请看下面的图片,你会得到一个想法。

您也可以尝试考虑以下选项(如果类别摘要是动态的):

【讨论】:

  • 我可以使用tableview单元格作为tableview的页眉和页脚吗?
  • 我想你可能可以,因为它只是 UIView 本身..
  • 同意。但在类别摘要中,您可以看到类别是动态的。检查类别下方有数量视图。 amountview 是固定的。如果我接受 headerview,它也会循环使用数组
  • 是的,您的类别摘要是动态的,好的,我会修改我的答案
  • 类别名称是动态的,totalview 是固定的
【解决方案2】:

使用UITableViewHeader 表示类别摘要,使用Sections 表示产品摘要。还要注意使用

tableView.dequeueReusableCellWithIdentifier("your_cell_identifier", forIndexPath: indexPath) as! YourTableViewCellClassName

而不是dequeueReusableCellWithIdentifier("your_cell_identifier")。后者有时容易出错。

【讨论】:

  • 当我使用两个 tableview 时,我遇到了身高问题。
  • 您不必使用两个UITableViews。而是可以使用相同的部分。
  • 我在类别摘要上方也有一个视图
  • 好吧。那么你能添加整个列表的模型吗?
  • this了解UI部分。但是您必须处理用于处理响应的数据结构
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多