objective-c - 从 UITableView 标题部分设置 UILabel 文本

标签 objective-c uitableview tableheader

我有一个分段的 UITableView 并想设置一个标签(不在 tableview 中)顶部标签的文本。

我尝试在

中使用 [label setText:@"name"]; 设置标签
 (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 

但这没有用。还有其他人知道如何执行此操作吗?

最佳答案

试试这个

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 60)];
    headerView.backgroundColor = [UIColor clearColor];

    UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0,0, 50, 50)];
    label.backgroundColor = [UIColor yellowColor];
    label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;

    [headerView addSubview:label];
    return headerView;
}

关于objective-c - 从 UITableView 标题部分设置 UILabel 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14482732/

相关文章:

ios - 如何通过在其上拖动 UIImageView 来获取 UITableView 的行索引

iphone - iPad/iPhone 多方向最佳实践?

iPhone 子类化 View Controller 和 IBOutlet UITableView

ios - 如何在 Swift 中从 Detail ViewController 更新 tableview 数组

sticky - 如何: Fixed Table Header with ONE table (no jQuery)

excel-2010 - 删除从 ClosedXML 中的 InsertTable 方法创建的表的所有格式

iOS-将图像制作为视频时,CVPixelBufferCreate 内存无法正确释放

ios - didSelectItemAtIndexPath 在 Collection View Swift 中不起作用

objective-c - Live Face Recognition iOS添加3D对象

css - 如何更改 antd 表格标题颜色