I have a UITableViewCell
subclass with a .xib
associated. I don't know why but after the init the table view remains empty with no cell. If I rotate the iPad the cell magically appears.
In viewDidLoad
I have registered table view to the .xib
- (void)viewDidLoad
{
self.tableView.allowsMultipleSelectionDuringEditing = YES;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.alpha = 0.0f;
[self.tableView registerNib:[UINib nibWithNibName:@"VirtualFileTableViewCell" bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:VirtualFileTableViewCellReuseID];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.tableView.contentInset = UIEdgeInsetsMake([self.topLayoutGuide length], 0.0f, [self.bottomLaoyout guide length], 0.0f);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake([self.topLayoutGuide length], 0.0f, [self.bottomLaoyout guide length], 0.0f);
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
[UIView animateWithDuration:0.5f animations:^{
self.tableView.alpha = ( self.viewType == ViewTypeList ? 1.0f : 0.0f );
} completion:^(BOOL finished) {}];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = VirtualFileTableViewCellReuseID;
VirtualFileTableViewCell * cell = (VirtualFileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.sizeLabel.text = @"5 KB";
return cell;
}
In other table view in the same project with the exactly same procedure all works fine. Ideas ?
Edit
I've notice another important detail. The problem is generated by this two line
self.tableView.contentInset = UIEdgeInsetsMake([self.topLayoutGuide length], 0.0f, [self.bottomLaoyout guide length], 0.0f);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake([self.topLayoutGuide length], 0.0f, [self.bottomLaoyout guide length], 0.0f);
in viewDidAppear
. I've tried to insert in viewDidLoad
and all works, but the problem is that I can't using topLayoutGuide
and bottomLayoutGuide
because in viewDidLoad
they haven't the correct value.
Instead if I use default cell without xib
this two line doesn't generate the problem and all work fine.