简体   繁体   中英

Remove view on top or bottom of Uitableview hosted on Uitableviewcontroller?

I am currently trying to remove the top or bottom view from my tableview but the size of the whole tableview isnt just right. Here is what i did so far.

  • Created a TableviewController inside the Storyboard
  • Created a Class derived from UITableViewController and set everything up like delegate etc.
  • Dragged a view to the top of the tableview inside the Storyboard
  • Created and connected an outlet named topview for this
  • In Viewwillappear i will remove that topview dependent of some value so i tried some things
 -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if(foo){ [self.topView setHidden:YES]; // or [self.topView removeFromSuperview]; // or [self.topView setFrame:CGRectMake(0, 0, 0, 0)]; } } 

For example if i remove the view from superview the topview isnt available anymore but there is a big gap on top .. how can i remove this top view from my tableview without having this gap ?

I put some Screenshots to describe my Problem:

我想更改俯视图的大小或完全删除它

在此处输入图片说明

If you put it inside the tableview it is probably the tableHeaderView. Try this:

self.tableView.tableHeaderView = nil;

Should remove the view and update the tableview accordingly.

[self.tableview reloadData]

删除topview后,或者如果您使用自动布局,则可以使用[self.view updateConstraints];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM