Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

KE5DXX

macrumors newbie
Original poster
Jun 20, 2010
21
0
Lubbock, TX
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!
 
Screenshot of Problem

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

Attachments

  • image1.jpg
    image1.jpg
    66 KB · Views: 184
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]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.