3

I have added a plain UITableView in my viewcontroller. Now I need to show both plain and group tableview in the same view controller for different criteria.

How can I convert the UITableView's style from plain to group in the same viewcontroller?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Nuibb
  • 1,800
  • 2
  • 22
  • 36

2 Answers2

5

If you are inheriting UITableViewController, you can just init tableView again.

Objective C:

self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];

Swift 4:

self.tableView = UITableView(frame: CGRect.zero, style: .grouped)
2

If you need same UITableView for both Grouped and Plain table then you can create it programmatically like

In Objective-C

UITableView *myTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];

In Swift

let tableView = UITableView.init(frame: CGRect.zero, style: .grouped)

else you can add two different UITableViews.

halfer
  • 19,824
  • 17
  • 99
  • 186
Hassy
  • 5,068
  • 5
  • 38
  • 63