cellForRowAtIndexPath not being called, but rowsInSections is and it's delegate is set
- by Jhorra
I searched around prior to posting this and made sure I hadn't missed anything obvious, though I have a feeling I am missing something basic.
I'm using this as a sidebar navigation view. I tried making them static cells and pre-populating them, but they were blank that way as well. When I do it this way I can see everything gets called except that. I've tried deleting it and re-adding it.
#import "acxSideBarController.h"
@interface acxSideBarController ()
@end
@implementation acxSideBarController
@synthesize sidebarDelegate = _sidebarDelegate;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if ([self.sidebarDelegate respondsToSelector:@selector(lastSelectedIndexPathForSidebarViewController:)]) {
NSIndexPath *indexPath = 0;
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
self.tableView.backgroundColor = [UIColor underPageBackgroundColor];
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section == 0)
return 2;
else if(section == 1)
return 1;
else
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"linkCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *name = @"";
if(indexPath.section == 1)
name = @"Inbox";
else if(indexPath.section == 2)
name = @"Logout";
else
{
if(indexPath.row == 0)
name = @"Roster";
else if(indexPath.row == 1)
name = @"Environmental Variables";
}
cell.textLabel.text = name;
cell.textLabel.textColor = [UIColor darkTextColor];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section == 0)
return @"Students";
else if(section == 1)
return @"Communication";
else
return @" ";
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.sidebarDelegate)
{
[self.sidebarDelegate acxSideBarController:self atIndexPath:indexPath];
}
}
@end
If it's helpful here's the header file
#import <UIKit/UIKit.h>
@protocol acxSideBarControllerDelegate;
@interface acxSideBarController : UITableViewController
@property (nonatomic, assign) id <acxSideBarControllerDelegate> sidebarDelegate;
@end
@protocol acxSideBarControllerDelegate <NSObject>
- (void)acxSideBarController:(acxSideBarController *)acxSideBarController atIndexPath:(NSIndexPath *)indexPath;
@optional
- (NSIndexPath *)lastSelectedIndexPathForacxSideBarController:(acxSideBarController *)acxSideBarController;
@end