Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header not visible in UITableView Controller

In my table view, i am setting the header title. But its not visible, i have to drag down the view to see and when i release it gets hidden and only the rows are visible. I want the header to be visible by default.

Here's the table view delegates i use:

- (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];


}
like image 684
Xavier Geoffrey Avatar asked Oct 25 '13 10:10

Xavier Geoffrey


People also ask

How does uitableviewcontroller work with a table view?

Table view controllers already adopt the protocols you need to manage your table view's content and respond to changes. In addition, UITableViewController implements the following behaviors: It automatically loads the table view archived in a storyboard or nib file. Access the table view using the tableView property.

How to add header and footer in UITableView?

There are two ways that we can add the header and footer, one way is to add it in using Interface Builder and the other way is to do it with code. In this tutorial we will be using both Interface Builder as well as code. The first thing that we need to do is to set up the UITableView and get it to show some data.

When to use subclass uitableviewcontroller in Salesforce?

Subclass UITableViewController when your interface consists of a table view and little or no other content. Table view controllers already adopt the protocols you need to manage your table view's content and respond to changes.

How to add a header to a Tableview in Interface Builder?

Ok, if you build and run the app it should look like this: Adding a header to the tableview in Interface Builder is easy, once you have your tableview drag a new view over the tableview towards the top, a blue line should appear, when it does you can place the view. See the below gif:


2 Answers

Please add this method:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
     return 100;
}
like image 163
Pradhyuman sinh Avatar answered Nov 02 '22 00:11

Pradhyuman sinh


Set the table view header height

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
   return 40; // What ever height you want.
}
like image 35
sbarow Avatar answered Nov 01 '22 22:11

sbarow