2012-02-12 49 views
8

我的URL映射如下:toSharedViewController未使用重新

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

,並在WebPageController

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

然後我叫網址幾次在我的代碼

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

爲什麼它沒有被緩存,因爲它是一個SharedViewController?

+0

執行什麼'WebPage'通過typedef來? – tonklon 2012-02-12 20:39:27

+0

@tonklon,它只是一個隨機ENUM – Howard 2012-02-13 17:07:47

+0

呵?........... – HelmiB 2012-02-17 11:37:27

回答

4

我相信這是發生在您身上的,因爲TTNaviagtor在iOS 5上壞了。請參閱https://github.com/facebook/three20/pull/719/files。你有沒有嘗試在iOS 4上運行相同的代碼,並得到相同的結果?

我向你推薦的是停止使用TTNaviagtor。您仍然可以通過在本地ios方法中推送並彈出TTViewController來使用three20庫。

這裏是在您的應用程序委託更換TTNaviagtor一個例子:

@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; 

而且

/////////////////////////////////////////////////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
@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; 
} 

那麼你可以把和彈出任何TTViewController(或您自己的TTViewController子類)進入_masterNavController 。就個人而言,我認爲TTNavigator是一種糟糕的設計模式,蘋果公司以不同的思維方式設計了他們的導航系統。

0

爲什麼不進入代碼並檢查發生了什麼?

我相信這些對象是在TTURLMap的objectForURL:query:pattern:中創建的,您可以設置一箇中斷點,看看爲什麼創建一個新的對象,而不是重新使用舊對象。

這個

objectForURL:query:pattern:與我的評論

- (id)objectForURL: (NSString*)URL 
      query: (NSDictionary*)query 
      pattern: (TTURLNavigatorPattern**)outPattern { 
    id object = nil; 
    if (_objectMappings) { 
    // _objectMappings is a NSMutableDictionary and use to cache shared object 
    object = [_objectMappings objectForKey:URL]; 
    // if object not found than check does _objectMappings contains it with right key 
    if (object && !outPattern) { 
     return object; 
    } 
    } 

    NSURL* theURL = [NSURL URLWithString:URL]; 
    TTURLNavigatorPattern* pattern = [self matchObjectPattern:theURL]; 
    if (pattern) { 
    if (!object) { 
     // object is not found in the mapping dictionary so create new one, this should only happen once for shared object 
     object = [pattern createObjectFromURL:theURL query:query]; 
    } 
    // make sure navigationMode is TTNavigationModeShare 
    if (pattern.navigationMode == TTNavigationModeShare && object) { 
     // cache shared object in the mapping dictionary so next time it will re-use the cached one 
     [self setObject:object forURL:URL]; 
     // if setObject:forURL: is not working than the shared object will not be cached 
    } 
    if (outPattern) { 
     *outPattern = pattern; 
    } 
    return object; 

    } else { 
    return nil; 
    } 
}