Krutarth Patel Krutarth Patel - 1 year ago 53
iOS Question

How to create Sections in Cell in Table View?

I am creating Receipt view, for this i am using tableview. I have created multiple cell to achieve this functionality.

Here is my code to use multiple cell:

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

and here is my screenshot what i exactly want in my tableview.

[![Receipt View][1]][1]

Data Structure

Amount = "39.5";
Numbers = 5;
Upgrade = 0;
UpgradeCount = 0;
"product_id" = 53;
Amount = "10.9";
Numbers = 1;
Upgrade = 0;
UpgradeCount = 0;
"product_id" = 60;

this is my category response

"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

I am able to do Category summary.

But in product summary you can see there are sections.

I am using only one tableview.

How i can create section for particular cell?

I take one cell of Product Summary.

I want only sections in this cell.

I want to create product summary according to screenshot.

Answer Source

Use UITableViewHeader for the category summary and Sections for the product summary. Also take care to use

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

rather than dequeueReusableCellWithIdentifier("your_cell_identifier"). The latter is found to be error prone at times.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download