I have a table in my viewController class
On tapping of a button (this button is outside of table), i wanted to show some UIView on top of tableView alone and a web service request is sent. After receiving the response, i want to remove the UIView which i have added.
tableView.addSubview(myview) didn't work for me, but self.view.addSubview(myview) worked but i wanted to overlay my UIView only on top of table view.
My question is specific to how to add/remove subview to a tableview. How can i achieve this?
Try like this for adding header on top
let headerView = UIView(frame: CGRect(x: XXX, y: YYY, width: XXX, height: YYY))
let imageView = UIImageView(frame: CGRect(x: XXX, y: YYY, width: XXX, height: YYY))
headerView.addSubview(imageView)
let labelView = UILabel(frame: CGRect(x: XXX, y: YYY, width: XXX, height: YYY))
headerView.addSubview(labelView)
self.tableView.tableHeaderView = headerView
It'll add header on UITableView
If you're using a UINavigationController with the table as one of it's view controllers, I have found the easiest way is to insert it here directly above the UITableView. This code could be called in your UITableViewController when you tap the button to display the view:
[self.navigationController.view addSubview:<your UIView>];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With