0

我有一个带有自定义表格视图单元格的表格视图。它用数据加载表格视图。但是当我尝试滚动它时它会变空。我正在将此表视图添加到这样的另一个视图中。它在我按下按钮后加载。

-(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
}
4

2 回答 2

0

在您的 IBAction 方法中,您没有使用 nextController 的属性,因此一旦该方法超出范围,它将被释放。为 nextController 创建一个属性(类型为 strong),这应该可以解决您的问题。

于 2012-10-17T00:15:49.203 回答
0

问题是当您滚动时,它不会重新加载,因为您刚刚添加了 nextController 的视图。一种解决方案是在同一个类中添加 tableview 及其委托方法,然后将其隐藏在 viewdidLoad 中。

- (void)viewDidLoad
{
    [super viewDidLoad];
    tableView.hidden = YES;
}

在 IBAction 上

tableView.hidden = NO;
[tableView reloadData];

在某处使用并再次隐藏它之后。希望这能解决你的问题。

于 2012-10-17T06:12:41.790 回答