2

如何在 iPhone SDK 中将 UITableview 的第一行设为静态(非滚动)?就像第一行将是静态的。

现在第一行是我的标题,我希望它需要是静态的意味着不能滚动?我已经有了节标题,因为我有行数。

4

3 回答 3

2

只需制作 2 个表格视图 - 一个在您的视图顶部,带有不可滚动的单元格,第二个 - 在第一个下方。

于 2012-05-31T05:36:20.297 回答
1

在下面的代码中,我正在为标题部分创建一个视图并添加标签和按钮..

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    // create the parent view that will hold header Label
    if (customView == nil) {
        customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)] ;
        // create the button object
        headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];

        headerLabel.backgroundColor = [UIColor clearColor];
        headerLabel.opaque = NO;
        headerLabel.textColor = [UIColor blackColor];
        headerLabel.highlightedTextColor = [UIColor whiteColor];
        headerLabel.font = [UIFont boldSystemFontOfSize:20];
        headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);

        // If you want to align the header text as centered
        // headerLabel.frame = CGRectMake(150.0, 0.0, 300.0, 44.0);

        headerLabel.text = [NSString stringWithFormat:@"Child: Name"];

        [customView addSubview:headerLabel];  

        UIButton *aReportButton = [UIButton buttonWithType:UIButtonTypeCustom];
        aReportButton.frame = CGRectMake(270, 3, 38, 38);
        [aReportButton setImage:[UIImage imageNamed:@"pdf_document.png"] forState:UIControlStateNormal];
        [aReportButton addTarget:self action:@selector(createPDF:) forControlEvents:UIControlEventTouchUpInside];
        [customView addSubview:aReportButton];
        aVoiceRecordingButton = [UIButton buttonWithType:UIButtonTypeCustom];
        aVoiceRecordingButton.frame = CGRectMake(220, 3, 38, 38);
        [aVoiceRecordingButton setImage:[UIImage imageNamed:@"microphone_document.png"] forState:UIControlStateNormal];
        [aVoiceRecordingButton addTarget:self action:@selector(alertBeforeRecord:) forControlEvents:UIControlEventTouchUpInside];

        [customView addSubview:aVoiceRecordingButton];
    }

    return customView;
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44.0;
}

在您的情况下,您必须增加表格部分标题高度以包括您的部分标题和您的第一个内容的UITableViewCell内容。希望这会有所帮助..

于 2012-05-31T05:36:31.273 回答
0

需要为第一个 tableviewCell 获取自定义视图并在 Header sectionView 中添加子视图

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

在标题视图下方设置自定义视图框架,并为标题视图正确设置剪辑绑定 NO。在标题视图中添加子视图自定义视图之后。

希望这会有所帮助。

于 2012-05-31T06:09:10.867 回答