1

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.

Fry
  • 6,235
  • 8
  • 54
  • 93

2 Answers2

4

Try to create object of custom cell VirtualFileTableViewCell * virtualFileTableViewCellObj in your TableView ".h" file and write following code in your cellForRowAtIndexPath :-

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = VirtualFileTableViewCellReuseID;

    if(virtualFileTableViewCellObj == nil)
        {
            virtualFileTableViewCellObj= (VirtualFileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        }


    virtualFileTableViewCellObj.sizeLabel.text = @"5 KB";

    return virtualFileTableViewCellObj;
}

Update:

Write the below mentioned lines in ViewDidAppear

self.tableView.delegate = self; 
self.tableView.dataSource = self; 

Hope it helps.

Rajat
  • 1,043
  • 12
  • 23
1

Please use this code

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"albumListCell";
   VirtualFileTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
   {
         cell = (VirtualFileTableViewCell *) [[[NSBundle mainBundle] loadNibNamed:@"VirtualFileTableViewCell" owner:self options:nil] lastObject];
   }
   return cell;
}

And Change in property of custom cell named "Identifier" eanter value "albumListCell"(withour quete) Because

static NSString *CellIdentifier = @"albumListCell";

enter image description here

Vishal
  • 159
  • 2
  • 12