5

在我的表格视图中,我正在设置标题标题。但它不可见,我必须向下拖动视图才能看到,当我释放它时它会被隐藏并且只有行可见。我希望标题默认可见。

这是我使用的表视图代表:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [arrayUseCases count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60; //row height
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    return @"General Cases";
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"UseCasesCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    UIView *bgColorView = [[UIView alloc] init];
    // Configure the cell...

    bgColorView.backgroundColor = [UIColor colorWithRed:90.0f / 255.0f green:120.0f / 255.0f blue:190.0f / 255.0f alpha:1.0f];
    bgColorView.layer.masksToBounds = YES;
    [cell setSelectedBackgroundView:bgColorView];

    NSString *rpcName = [self.arrayUseCases objectAtIndex:[indexPath row]];

    [[cell textLabel] setText:rpcName];
    [[cell textLabel] setFont:[UIFont fontWithName:@"ChalkBoard SE" size:18]];
    cell.textLabel.textColor = [UIColor colorWithRed:90.0f / 255.0f green:120.0f / 255.0f blue:190.0f / 255.0f alpha:1.0f];


    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Clicked table view in GeneralUseCase View");
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    [[self navigationController] pushViewController:[storyBoard instantiateViewControllerWithIdentifier:@"LogViewID"] animated:YES];

    NSIndexPath *index = [self.tableView indexPathForSelectedRow];

    dic = [[NSDictionary alloc] initWithObjectsAndKeys:index,@"Index", nil];

    [self performSelector:@selector(postUseCaseNotification) withObject:nil afterDelay:1.0];

    //to deselect the selected row when view comes back
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];

    //    [[NSNotificationCenter defaultCenter] postNotificationName:LogViewControllerGeneralUseCaseNotification object:self userInfo:dic];


}
4

3 回答 3

16

请添加此方法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
     return 100;
}
于 2013-10-25T10:30:57.383 回答
7

设置表格视图标题高度

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
   return 40; // What ever height you want.
}
于 2013-10-25T10:28:00.323 回答
3

您忘记实现此方法 (tableView:heightForHeader:) - 它返回标题的高度。否则它返回 0,这就是它不被渲染的原因:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40; // or whatever height you want
}
于 2013-10-25T10:29:33.517 回答