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:
and my .m file with the methods pertaining to the problem:
Any ideas? Thanks!
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!