Alan Carter
Alan Carter

Reputation: 223

Tableview reloadData is not being executed -- sometimes

I have a view controller that is called from 2 different places.

1) I call it from a root controller. It is shown and populated. The add button works perfectly. I open a modal form, get the information and return it to the view controller via it's delegate.

- (void)itemsAddViewController:(AddItemView *)itemsAddViewController didAddItem
  (OrdersDetails *)orderDetail;
{
    if (orderDetail) {
        [orderDetailItems addObject:orderDetail];
}   
[self fetchOrderDetails];
[lineItemsTableView reloadData];
[self dismissModalViewControllerAnimated:YES];

}

However, when I call it from another view (on the right side of the split view), this same code does NOT reload the table. It adds the data -- if I leave the form and come back, the data is there, but the tableview is not being refreshed. When I step through the code, it gets the the line, but then goes over it like it doesn't see it.

Upvotes: 0

Views: 1615

Answers (1)

Jonah
Jonah

Reputation: 17958

When a modal view controller is presented over the view controller containing -itemsAddViewController:didAddItem: the underlying controller's view is not visible and will therefore be unloaded if the controller receives a memory warning.

As a result your view may not be loaded and your lineItemsTableView outlet may be nil when you call -itemsAddViewController:didAddItem:. Your call to reloadData would need to move to -viewWillAppear: to avoid assuming that your controller's view can have a persistent state when it is not visible.

Upvotes: 1

Related Questions