Reputation: 308
I have used the UITableViewController before though most of it was with Nibs and not the Storyboard and i cant seem to get it to populate the look or the data.
My UITableViewController is set up like the below:
@implementation BFTBackThreadTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_dummyUsers = [[NSArray alloc] initWithObjects:@"@JonathanB",@"@NickyV",@"@Dman",@"C-LO-P", nil];
NSLog(@"%lu", (unsigned long)[_dummyUsers count]);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_dummyUsers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BFTThreadTableViewCell *cell = (BFTThreadTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
// Configure the cell
cell.userLabel.text = [_dummyUsers objectAtIndex:[indexPath row]];
return cell;
}
I have checked the array and all 4 objects are in there, so they should be able to populate the Row.
My UITableViewCell class.h file is set up like so:
@interface BFTThreadTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *userLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeStamp;
@property (weak, nonatomic) IBOutlet UIButton *numberMessageThread;
@end
All of those Outlet's are connected to the Cell in the Storyboard and show the connection when using the assistant editor. The cellIdentifier is correct and made sure i copy and pasted instead of trying to type it correctly each time.
The storyboard is set up like so:
Though to my knowledge i believe this should be working and i still cant get it to work, it keeps running to look like the below on the emulator:
Any help would be greatly appreciated. Thank you in advance!
Upvotes: 0
Views: 2021
Reputation: 773
I spent DAYS trying to find a solution to this.
I know I'm late to the game (and it certainly wasn't the reason why Keeasno's prototype cells weren't displaying) but if the answer above doesn't help the solution to my problem was that I was using the wrong "identifier" field in Interface Builder. Make sure in the Interface builder that you are using the correct "identifier" field to provide your reusable identifier, see below:
XCode Interface Builder Sceenshot
The Accessibility Identifier has nothing to do with prototype cells - it has to do with providing useful information for users requiring accessibility features (e.g. voice over assistance), see link below for more info:
Making Your iOS App Accessible
Upvotes: 1
Reputation: 906
In my logic, for responding to the tableView:cellForRowAtIndexPath: if dequeueReusableCellWithIdentifier returns a nil value, I create an instance myself. The code looks like this:
static NSString *cellIdentifier = @"CellIdentifier";
MaterialTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier: cellIdentifier];
if (cell == nil)
cell = [[MaterialTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:
cellIdentifier];
Upvotes: 0
Reputation: 8576
You are returning zero for the number of sections in your table view, therefore it's not showing any sections. Use this:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
Upvotes: 2
Reputation: 104092
You have to return a non-zero number in numberOfSectionsInTableView: or just delete the method entirely which will default to 1 section.
Upvotes: 3