我想在UITableView的页脚中显示UIButton(应该与页眉完全相同)。UITableView tableFooterView奇怪的调整大小
此代码是我TableViewController的viewDidLoad中:
UIButton *footerShareButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[footerShareButton setFrame:CGRectMake(10, 0, 70, 50)];
NSLog(@"%f", footerShareButton.frame.size.width);
[self.tableView setTableFooterView:footerShareButton];
NSLog(@"%f", footerShareButton.frame.size.width);
NSLog(@"%f", self.tableView.tableFooterView.frame.size.width);
但是,此代码不能正常工作。 Button的宽度太大了,它是320.(高度是正确的。)第一个NSLog输出70,第二个和第三个输出320.所以看起来setTableFooterView方法奇怪地调整了按钮的大小。
我已经把UIButton的在另一个的UIView它设置为表前躯解决了这个问题:
UIButton *footerShareButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[footerShareButton setFrame:CGRectMake(10, 0, 70, 50)];
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 70, 50)];
[aView addSubview:footerShareButton];
[self.tableView setTableFooterView:aView];
[aView release];
这个作品中,按钮有正确的宽度。
但是,我不明白为什么第一个代码示例不起作用。谁能解释一下?
没错,就是这样,它调整我创建和看法,我只是没有注意到。谢谢。我认为应该在文档中提到设置tableFooterView属性调整视图的大小,这会节省一些时间。 – avf 2010-07-19 14:26:49