我有一个具有 tableView 的 UITableViewController。对于这个 tableView,我想添加一个标签和一个按钮,但不幸的是,我只能添加一个或另一个。
这是我正在使用的代码:
- (void) viewDidLoad {
[super viewDidLoad];
selectAllButton = [UIButton buttonWithType:UIButtonTypeCustom];
[selectAllButton setFrame:CGRectMake(280, 0, 25, 25)];
[selectAllButton setImage:[UIImage imageNamed:@"CheckBox1.png"] forState:UIControlStateSelected];
[selectAllButton setImage:[UIImage imageNamed:@"CheckBox2.png"] forState:UIControlStateNormal];
[selectAllButton setUserInteractionEnabled:YES];
[selectAllButton addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
selectAllLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 40)];
[selectAllLabel setTextColor:[UIColor blackColor]];
[selectAllLabel setBackgroundColor:[UIColor clearColor]];
[selectAllLabel setText:@"Select All"];
self.tableView.tableHeaderView = selectAllButton;
self.tableView.tableHeaderView = selectAllLabel;
}
当我运行上述方法时,我只能看到我的标签,它告诉我它正在替换按钮。有没有办法让两个元素都出现在 tableheaderview 中?