【发布时间】:2014-01-14 12:10:51
【问题描述】:
我有一个带有 1 个部分的 UITableView,对于部分标题,我想保持标题的所有内容相同,但只需在右侧添加一个按钮。我无法将按钮放在导航控制器中,因为放置此类按钮的两个可用位置已被其他按钮占用。
在这里你可以看到我尝试做的结果。现在我要做的就是在标题的右侧放置一个添加按钮,但我尝试过的没有奏效。我还在 StackOverflow 上尝试了其他一些解决方案,但它们并没有完全完成我想做的事情。此外,如果有更好的方法来创建添加按钮,请告诉我。我尝试使用UIBarButtonItem,但我不知道如何将其视图添加到实际视图中。谢谢!
这是我目前在我的代表中所拥有的:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIButton *addButton = [[UIButton alloc] init]; //I also tried setting a frame for the
button, but that did not seem to work, so I figured I would just leave it blank for posting
the question.
addButton.titleLabel.text = @"+";
addButton.backgroundColor = [UIColor redColor];
[self.tableView.tableHeaderView insertSubview:addButton atIndex:0];
//I feel like this is a bad idea
return self.tableView.tableHeaderView;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 50;
}
【问题讨论】:
标签: ios objective-c uitableview uiview uibutton