iphone - UITableView tableFooterView weird resizing -


I want to display UIButton in the footer of a UITableView (should be exactly the same for the header).

This code is in ViewDidLoad of my TableViewController:

  UIButton * footerShareButton = [UIButton button with type UIButtonTypeRoundedRect]; [Padherabithton setframe: CGRactam (10, 0, 70, 50)]; NSLog (@ "% F", padcherbiton.fr. size.width); [Self-TailviewviewTableWaterWaterView: PaderSabetan]; NSLog (@ "% F", padcherbiton.fr. size.width); NSLog (@ "% f", self.tableView.tableFooterView.frame.size.width);  

However, this code does not work. The width of the button is too large, it is 320. (Although the height is correct.) The first NSLog 70, the second and third output makes 320. So it seems that the size of the odd button resembles the setTableFooterView method.

I have fixed this problem by setting UIButton as a table footer in another UIView:

  UIButton * footerShareButton = [UIButton buttonWithType: UIButtonTypeRoundedRect]; [Padherabithton setframe: CGRactam (10, 0, 70, 50)]; UIView * aView = [[UIView alloc] initWithFrame: CGRectMake (10, 0, 70, 50)]; [AView addSubview: PaderSabetan]; [Self-Tables Wise Set Tablesfooter View: AVII]; [AView release];  

This works, the button has the right width.

However, I do not understand why the first code sample does not work. Can anyone explain?

There is no mater that you set in the view that you have a table footer Adding / Header - Its width will always be in the form of table width

Therefore, whatever scenario you have added in your case has been changed to CGRectMake (0, 0, 320, 50) , but the button with the correct frame The frame of the remains button is according to the view ...

edit :
The only parameter in the footer / header frame that you have set That's the height.

Notice that if you change the title / footer view height after adding it to the table, then it will not make any changes. You should set the height before adding it to the table ...


Comments