ios - 如何在 TableView 中的单元格中创建部分?

标签 ios swift uitableview

我正在创建收据 View ,为此我使用表格 View 。我创建了多个单元来实现此功能。

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

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

这是我在桌面 View 中真正想要的屏幕截图。

[![收据 View ][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
]

我能够进行类别摘要。
但在产品摘要中您可以看到有几个部分。

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

最佳答案

使用 UITableViewHeader 作为类别摘要,使用 Sections 作为产品摘要。还要注意使用

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

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

关于ios - 如何在 TableView 中的单元格中创建部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40020007/

相关文章:

ios - 在 ios 上调用 dlopen

Swift - animateWithDuration 完成访问错误

ios - 设置单元格圆角和边框宽度使表格 View 滚动速度极慢

ios - swift : boundingRectWithSize return wrong height for a multiline label

ios - 根据行数更改 UITableView 的大小

ios - pushViewController 不做任何 Action

swift - 删除 isLeapMonth : false

ios 在 UITableView 标题 View 中添加一个 uicollectionView

iOS 界面生成器 : SearchBar wont show when y position is changed

Ios - 如何在不同的 View Controller 中启动计时器