Question

I am trying to insert rows in the TableViewController's tableView Object from other class using

UINavigationController *navigationController = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    ReceiptHomeTableViewController *homeTableViewController= (ReceiptHomeTableViewController*)navigationController.viewControllers[0];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:([[PersistenceService getInstance] count]-1) inSection:0];
    [homeTableViewController.tableView insertRowsAtIndexPaths:@[indexPath]
                                             withRowAnimation:UITableViewRowAnimationNone];

I have also tried using

//[homeTableViewController.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
//[homeTableViewController.tableView reloadData];

but the HometableViewContoller only shows the rows that fit in the screen width. I try to scroll to bottom, but it don't go to last row. Scrolling works perfect if I restart the application and cells are created using ellForRowAtIndexPath: method, but fails to work if I add new rows.

It seems like UI is not updated about the new length of the View when a row is added. Any help?

Was it helpful?

Solution 2

I found the problem. I had autolayout turned on by default on tableviewcontroller. turning it off worked for me.

Thanks for the sihhestions

OTHER TIPS

Due to below 50 reputation, i won't able to give comments. So i like to give suggestion about this question in answer section.

From your question, you must post cellForRowAtIndexPath method. Then only clue will click. And please NSLog your new row objects in the view where the tableCell sub viewed.

After you edit your post, I'll give answer in this post by edit if i got answer or any clue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top