我无法弄清楚为什么我的自定义TableViewCell
中的UILabel在CellForRowAtIndexPath中为零。我在另一个视图Controller中使用了与之前的TableView相同的方法。这是我已经检查的内容:
我可以更改单元格的背景颜色并填充textLabel.text - 它只是我的UILabels
未填充。
这是CellForRowAtIndexPath
。它与我的其他TableVC
完全相同,可行。另外,如果我使用不同的方法,我不需要实际重用这个自定义单元格吗?
- (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;
}
非常感谢。
.h文件:
@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文件:
@implementation ProfileSection0TableViewCell
@synthesize labelName, labelSpecialty, labelPosition, facePicture, labelCurrentRole;
@end
编辑:
看起来ProfileSection0TableViewCell分配正确,但单元格内的成员变量为零。在网点,这里是连接:
答案 0 :(得分:1)
_userProfile.fullName
为nil
或profilecell.labelName
为nil
如果您在界面构建器中创建了单元格,是否正确地将插座连接到labelName
?