开发者

UISpliviewcontroller in recursive calls fail after a memory warning

Any help is appreciated ! It's several days I'm fighting w/o results.

The scenario:

I开发者_运维技巧 and iPad application have a SplitViewController that shows 2 controllersViews (Root on the left e Detail on the right)

The Root allows a recursive navigation (tree that could be several drilldown levels) and I'm calling every time the same controller class (UITableView) pushing always in the controller stack). When the user taps a cell (left side), the detail view (right side) shows the information. Keep in mind that the detail view controller is not always the same class: it means that I'm allocating (and releasing) programmatically several detailView controllers according the kind of information I have to display.

Here the fragment:

UIViewController <ItemGenericViewController> *newDetailViewController = [[NSClassFromString(cntrClass) alloc] initWithNibName:cntrXib bundle:nil];

//the detailViewController has been defined in the head section as ItemGenericViewController

//each detailViewController is a subclass of ItemGenericViewController

detailViewController = newDetailViewController;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:detailViewController];

// Update the split view controller's view controllers array.

NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, nav, nil];
self.splitViewController.viewControllers = viewControllers;
[nav release];
[viewControllers release];
[detailViewController release];

Everything is working fine until a memory warning arises.

From that moment if I try to display a new detailViewcontroller the "connection" in the SplitViewController, between the RootController and the detailController, seems vanished. The result is: nothing appear on the right part of the splitController. In the mean time if I navigate to parent level in the root controller the situation still failing.

For your information each time I push in the stack a new RootController instance (left column) I'm releasing the same controller (to save memory as usual) and I suspect, after receiving the memory warning, iOS is trying to free itself memory and my "history" disappear and the related connection, throught the split controller, too.

Is a nightmare ;-)

Do you have any suggestion ?

Thanks

Dario


I had a similar problem to you (maybe even worse - 16 combinations of possible view switches)... But I believe i have solved it right now.

So, i believe you have used Apple's example for view switching (I have, with modifications), and if you have so, problem is that "root" splitViewController (from MainWindow.xib) get's "niled" as default behavior when memory warning. And even if you add new array of view controllers to it, it will not cause any change (and even worse, it will not show any sign of warning). And solution is to check is it nil, and if is, to reinitialize it.

here is the code, using example from above:

 UIViewController <ItemGenericViewController> *newDetailViewController =  [[NSClassFromString(cntrClass) alloc] initWithNibName:cntrXib bundle:nil];

//the detailViewController has been defined in the head section as ItemGenericViewController

//each detailViewController is a subclass of ItemGenericViewController

detailViewController = newDetailViewController;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:detailViewController];

// Update the split view controller's view controllers array.

NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, nav, nil];

/**** Milos Edit ****/
if (self.splitViewController == nil) {
    // I'm keeping reference in app delegate, but any way to reinitialize splitViewController is OK
    self.splitViewController = delegate.splitViewController;
}
/**** end of edit ****/
self.splitViewController.viewControllers = viewControllers;
[nav release];
[viewControllers release];
[detailViewController release];

Hope it will be helpful.

Cheers

Milos

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜