0
votes

In my storyboard I have UITableViewController which has custom class. How can I add UIView objects on top and bottom parts of the table view?

Do I have to create UITableView and two desired views inside of UIView and then manually init my controller, set tableView or there is a better way?

3
do you want to add the views into the header/footer of the first/last section? then you could use the UITableViewDelegate's methods tableView:viewForHeaderInSection: and tableView:viewForFooterInSection:lootsch
Depends if you want the views to scroll with the view or notgiorashc
I want the views to be static, not scroll and not obscure table items.Pablo

3 Answers

2
votes

If you're wanting to use UITableViewController for it's abilities to manage cells and static layouts, the best possibility would be to use a container view in your storyboard. This would allow you to layout the main view contents around the table and still keep a separate UITableViewController maintaining the table itself. Set up the right auto layout constraints (really simple, just anchor the container view to the header and footer views)

enter image description here

0
votes

Yes it's possible in UITableViewConroller:

    let bottomView = UIView()
    bottomView.backgroundColor = .red // or your color
    bottomView.frame = CGRect(x: 0, y: UIScreen.main.bounds.size.height - 78, width: tableView.frame.size.width, height: 78) // 78 or your size of view
    navigationController?.view.addSubview(bottomView)
    tableView.tableFooterView = UIView()

enter image description here

-2
votes

Something like this should work for you:

// Your frame/view will vary
UIView *subview = [[UIView alloc]initWithFrame:CGRectMake(0, 64, 320, 44)];
subview.backgroundColor = [UIColor redColor];

[self.navigationController.view addSubview:subview];