我有一个带有自定义表格视图单元格的表格视图。它用数据加载表格视图。但是当我尝试滚动它时它会变空。我正在将此表视图添加到这样的另一个视图中。它在我按下按钮后加载。
-(IBAction)chooseFirstController:(id)sender {
UIViewController *nextController = [[FirstController alloc] initWithNibName:@"FirstController" bundle:nil];
[self.contentView addSubview:nextController.view];
}
对于我的 tableview,我有这个方法。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"StaffCustomCell";
StaffCustomCell *cell = (StaffCustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StafCustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
Staff *staff = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.lblName.text = staff.name;
cell.lblGeboortePlaats.text = staff.birthplace;
cell.lblGeboorteDatum.text = staff.birthday;
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.fetchedResultsController.sections count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
NSInteger count = [sectionInfo numberOfObjects];
return count;
}
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = self.fetchedResultsController.sections[section];
return [sectionInfo name];
}
有人可以帮忙吗?
亲切的问候。
编辑
在这里你可以看到我的 staffCustomCell.m
#import "StaffCustomCell.h"
@implementation StaffCustomCell
@synthesize lblContract = _lblContract;
@synthesize lblDebuut = _lblDebuut;
@synthesize lblFunction = _lblFunction;
@synthesize lblGeboorteDatum = _lblGeboorteDatum;
@synthesize lblGeboortePlaats = _lblGeboortePlaats;
@synthesize lblKinderen = _lblKinderen;
@synthesize lblName = _lblName;
@synthesize lblNationaliteit = _lblNationaliteit;
@synthesize lblPartner = _lblPartner;
@synthesize lblVorigeClubsS = _lblVorigeClubsS;
@synthesize lblVorigeClubsT = _lblVorigeClubsT;
@synthesize imgTrainer = _imgTrainer;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor blackColor];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}