Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toSharedViewController not re-using existing controller

My URL map is as follows:

[map from:@"tt://webPage/(initWithPage:)" toSharedViewController:[WebPageController class]];

and in the WebPageController

- (id) initWithPage:(WebPage)page
{
    if (self = [super init])
    {
    ...

Then I called the url several times in my code

tt://webPage/1
tt://webPage/2
tt://webPage/1 (still called the initWithPage: everytime, not cached)

Why it is not cached as it is a SharedViewController?

like image 552
Howard Avatar asked Feb 12 '12 03:02

Howard


1 Answers

I believe this is happening to you because TTNaviagtor is broken on iOS 5. see https://github.com/facebook/three20/pull/719/files. Have you tried running the same code on a iOS 4 with the same result?

My recommendation to you is to stop using TTNaviagtor. You can still use the three20 library by pushing and poping TTViewController in the native ios method.

Here's an example on replacing the TTNaviagtor in your app delegate:

@interface AppDelegate : NSObject <UIApplicationDelegate> {

 UIWindow* _window;
 TTBaseNavigationController* _masterNavController;
 WebPageController* _web1Controller;
 WebPageController* _web2Controller;
}

@property(nonatomic, retain) UIWindow* window;
@property(nonatomic, retain) TTBaseNavigationController* masterNavController;
@property(nonatomic, retain) WebPageController* web1Controller;
@property(nonatomic, retain) WebPageController* web2Controller;

And

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation AppDelegate

@synthesize window = _window;

@synthesize masterNavController = _masterNavController;
@synthesize web1Controller = _web1Controller;
@synthesize web2Controller = web2Controller;

///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)application:(UIApplication *)application 
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  _window = [[UIWindow alloc] initWithFrame:TTScreenBounds()];


    TTViewController* controller = [[[MasterViewController alloc] init] autorelease];
    _masterNavController = [[TTBaseNavigationController alloc] initWithRootViewController:controller];
    [_window addSubview:_masterNavController.view];    
  }

  [_window makeKeyAndVisible];

  return YES;
}

then you can push and pop any TTViewController (or your own subclasses of TTViewController) into the _masterNavController. Personally, i think TTNavigator is a bad design pattern, and apple designed their navigation system in different mindset.

like image 113
aporat Avatar answered Oct 06 '22 00:10

aporat