2012-02-12 1 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) 
URLを呼ばれます

SharedViewControllerとしてキャッシュされないのはなぜですか?

+0

objectForURL:query:pattern:の実装は何? – tonklon

+0

@tonklon、それはちょうどランダムENUM – Howard

+0

ハァッですか?........... – HelmiB

答えて

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

、あなたが_masterNavControllerに任意のTTViewController(またはTTViewControllerの独自のサブクラス)を押すと開くことができます。個人的には、TTNavigatorは悪いデザインパターンだと思うし、リンゴはナビゲーションシステムを別の考え方で設計した。

0

なぜコードにステップインして何が起きていないか確認してください。

私はオブジェクトがTTURLMapのobjectForURL:query:pattern:で作成されたと信じています。ブレークポイントを設定して、新しいものが作成された理由を知ることができます。 `WebPage`がにtypedefedさ

この私のコメント

- (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; 
    } 
} 
関連する問題