Blank Section Header for UITableView?

Discussion in 'iOS Programming' started by KE5DXX, Nov 18, 2010.

  1. KE5DXX macrumors newbie

    Joined:
    Jun 20, 2010
    Location:
    Lubbock, TX
    #1
    Hello all!

    I am creating a navigation based app in which there is a UITableView loaded up programatically for one of the view controllers. However, when the app loads, there is what appears to be a blank section header at the top of the list of objects. I have no idea how to get rid of this, as I've never experienced it in anything I've programmed with before. This could be an amateur question, but I like to think questions lead to wisdom.

    Here is my code:

    My .h file:
    Code:
    #import <UIKit/UIKit.h>
    #import "NewsRetriever.h"
    #import "NewsDetailViewController.h"
    
    @interface NewsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
    	UITableViewController *tableController;
    	NewsRetriever *myNewsRetriever;
    	NSArray *myArticleTitles;
    	NSArray *myArticleAuthors;
    	NSArray *myArticleDates;
    	NSArray *myArticleBodies;
    }
    
    @end
    
    and my .m file with the methods pertaining to the problem:

    Code:
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
        if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
    		tableController  = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    		tableController.tableView.delegate = self;
    		tableController.tableView.dataSource = self;
    		myNewsRetriever  = [[NewsRetriever alloc] init];
    		[myNewsRetriever parseArticles];
    		myArticleTitles  = [[NSArray alloc] initWithArray:[myNewsRetriever articleTitles]];
    		myArticleAuthors = [[NSArray alloc]initWithArray:[myNewsRetriever articleAuthors]];
    		myArticleDates   = [[NSArray alloc] initWithArray:[myNewsRetriever articleDates]];
    		myArticleBodies  = [[NSArray alloc]initWithArray:[myNewsRetriever articleBodies]];
    	}
        return self;
    }
    
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];
    	
    	self.title = @"The|Ridge News";
    	
    	UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:nil action:nil];
    	self.navigationItem.rightBarButtonItem = item;
    	[item release];
    		
    	NSLog(@"table section header height = %f", tableController.tableView.sectionHeaderHeight);
    	
    	[self.view addSubview:tableController.tableView];
    }
    
    // Customize the number of sections in the table view.
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    	return [myArticleTitles count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        }
    
    	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    	cell.textLabel.text = [myArticleTitles objectAtIndex:indexPath.row];
    	cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", [myArticleAuthors objectAtIndex:indexPath.row], [myArticleDates objectAtIndex:indexPath.row]];
    	
    	return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	NewsDetailViewController *newDetail = [[NewsDetailViewController alloc] initWithTitle:[myArticleTitles objectAtIndex:indexPath.row]
    																											   andAuthor:[myArticleAuthors objectAtIndex:indexPath.row]
    																												 andDate:[myArticleDates objectAtIndex:indexPath.row]
    																												 andBody:[myArticleBodies objectAtIndex:indexPath.row]
    																											  andNibName:@"NewsDetailViewController"
    																											   andBundle:[NSBundle mainBundle]];
    	[self.navigationController pushViewController:newDetail animated:YES];
    	[newDetail release];
    }
    
    Any ideas? Thanks!
     
  2. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
  3. KE5DXX thread starter macrumors newbie

    Joined:
    Jun 20, 2010
    Location:
    Lubbock, TX
    #3
    Screenshot of Problem

    Here is the best screenshot I could get. Notice the extra blank space above the first item:
     

    Attached Files:

  4. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #4
    My first advice would be to not use a direct subclass of UIViewController that points to a UITableViewController. Your custom view controller should probably just be a subclass of UITableViewController directly. Unless there's some crazy custom functionality that you need and this is the only way to make it happen, it's not a very clean approach.

    The problem might be coming from:
    [self.view addSubview:tableController.tableView]
     

Share This Page