ios - 在 TableView 的开头设置标题的位置

标签 ios objective-c uitableview

我必须在 TableView 的开头设置我的 headerView。 它似乎已修复,请帮助。

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.frame.size.width,40)] autorelease];
    headerView.backgroundColor = [Utility consumerLightColor];
    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 250, headerView.frame.size.height)];
    headerLabel.text = @"Upcoming Appointments";
    headerLabel.textAlignment = NSTextAlignmentLeft;
    headerLabel.textColor = [UIColor whiteColor];
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
        headerLabel.font = [UIFont fontWithName:@"bauhaus md bt" size:15.0f];
    }
    else{
        headerLabel.font = [UIFont fontWithName:@"bauhaus md bt" size:16.0f];
    }

    // // NSLog(@"title --> %@",[locationArray objectAtIndex:i]);

    headerLabel.backgroundColor = [UIColor clearColor];
    [headerView addSubview:headerLabel];
    [headerLabel release];



    return headerView;

}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (tableView == appointmentListtableView) {
        CGFloat changeheight = 40.00;
        return changeheight;
    }
    else{
        return 0.0f;
    }

}

enter image description here

enter image description here

我只想将标题 View (即将到来的约会)的位置设置在表格 View 的开头,它不应该是固定的。

最佳答案

也许您需要删除表头,而不是节头? 为此,您需要设置:

tableView.tableHeaderView = nil

关于ios - 在 TableView 的开头设置标题的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42454319/

相关文章:

ios - 在行的按钮附近添加一个 UIView?

ios - 如何在 UITableView 中使用两个不同的自定义 UITableViewCell?

ios - 带有声音/音频的 NSMutableAttributedString

ios - 从文本字段中删除圆角,保持背景不透明度 iOS Swift

ios - 使用 For 循环在 UISlider 上绘制线条

iphone - NSDictionary 或 NSKeyedArchiver

ios - ios 上的后台 http 请求为 "killed app"

swift - 如何将工具栏放置在滚动 TableView 上方(或下方)

android - PhoneGap 构建插件

ios - 如何将 NSMutable 字符串附加到 UILabel