3

This is driving me nuts. I am using three20's TTTableViewController and when I get a memory warning, the screen goes white. Now, after reading on the three20 google group is seems that the tableView got released. But, I cannot for the life of me figure out a check to see if that is the case, then create it again.

I was using the following because I thought it would fix the issue, but it seems that it doesn't satisfy the if statement:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // If we don't have a datasource we need to reset it
    if (!self.dataSource) {
        // Create datasource again
    }

}//end

Does anyone know what to do when this happens? The google group has been no help.

Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412

3 Answers3

0

Are you subclassing TTTableViewController? I haven't used it before, but assuming it's just like UITableViewController...

How does your "viewDidUnload" look like? Are you releasing the tableview here? If so, you need to create tableview in viewDidLoad to match it.

No need to check if dataSource is available in viewDidAppear, because if you read View programming guide, it explains that memory warning will call "viewDidUnload" to give you a chance to clean up data that are created in "viewDidLoad".

Sean S Lee
  • 1,274
  • 9
  • 24
0

i had the same issue and it drove me crazy as well.

Nobody mentions it in the three20 docs, but you shouldn't use UIViewController's initWithNibName function to add subviews. If you do, a memory warning will release these subviews.

Try to move your code from initWithNibName function to viewDidLoad function. I have noticed that some code need to be kept in the initWithNibName, such as navigation styles. However, any subviews added to the controller's view should be in the viewDidLoad function.

aporat
  • 5,922
  • 5
  • 32
  • 54
0

In general you should be careful to set up views in viewDidLoad rather than the class constructor. For instance, you should set up your launcher view in viewDidLoad rather than the constructor of your launcher view controller, otherwise your launcher will become empty after a memory warning.

In the case of TTTableViewController however this does not (usually) apply because you don't set up the table view manually. I had the same problem you had, and eventually tracked it down: I had redefined viewWillDisappear: and forgot to call [super viewWillDisappear:animated]. This meant that some of the flags that the Three20 controller maintains about the state of the view were not updated correctly.

I also found that it was beneficial to redefine didReceiveMemoryWarning to call [self setEditing:NO] before calling super; I found that the state of the table view got confused otherwise (this is not relevant if you don't use edit mode for your table).

Finally, there is a bug in Three20 which means that tables in loading/empty/error mode will not be restored properly; see a discussion in the blog post by TwoCentStudios and a proposed fix on github.

edsko
  • 1,628
  • 12
  • 19