Reputation: 1
I can't figure out why my UILabels in my custom TableViewCell
are nil in CellForRowAtIndexPath. I used the same method as I did for a previous TableView in another view Controller. Here's what I already checked:
I am able to change the background color of the cell and populate the textLabel.text -- it's just my UILabels
that aren't filled.
Here is CellForRowAtIndexPath
. It's the exact same method as my other TableVC
, which works. Also, I don't need to actually reuse this custom cell, should I be using a different method?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifierProfile = @"profilecell";
ProfileSection0TableViewCell *profilecell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierProfile];
if (profilecell == nil) {
profilecell = [[ProfileSection0TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifierProfile];
}
if (indexPath.section == 0) {
[profilecell setBackgroundColor:[UIColor colorWithRed:54/255.0f green:61/255.0f blue:147/255.0f alpha:1.0f]];
if (indexPath.row == 0) {
profilecell.labelName.text = _userProfile.fullName;
NSString *test = [NSString stringWithFormat:@"%@", profilecell.labelName.text];
NSLog(@"text %@", test); //shows that label is (null)
profilecell.labelName.textColor = [UIColor whiteColor];
//profilecell.labelSpecialty.text = _userProfile.specialty;
//profilecell.labelSpecialty.textColor = [UIColor whiteColor];
}
}
return profilecell;
}
Thanks so much in advance.
.h file:
@interface ProfileSection0TableViewCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel* labelName;
@property (nonatomic, weak) IBOutlet UILabel* labelSpecialty;
@property (nonatomic, weak ) IBOutlet UILabel* labelCurrentRole;
@property (nonatomic, weak) IBOutlet UILabel* labelPosition;
@property (nonatomic, weak) IBOutlet UIButton* facePicture;
@end
.m file:
@implementation ProfileSection0TableViewCell
@synthesize labelName, labelSpecialty, labelPosition, facePicture, labelCurrentRole;
@end
EDIT:
It looks like ProfileSection0TableViewCell is allocated properly, but the member vars inside the cell are nil. And in outlets, here are the connections:
Upvotes: 0
Views: 786
Reputation: 12668
Either _userProfile.fullName
is nil
or profilecell.labelName
is nil
If you made the cell in interface builder, did you hook up the outlet to labelName
correctly?
Upvotes: 1