2012-02-12 37 views
8

đồ URL của tôi là như sau:toSharedViewController không tái sử dụng bộ điều khiển hiện

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

và trong WebPageController

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

Sau đó, tôi gọi là url nhiều lần trong mã của tôi

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

Tại sao nó không được lưu trong bộ nhớ cache vì nó là một SharedViewController?

+0

gì là 'WebPage' typedefed tới? – tonklon

+0

@tonklon, nó chỉ là một ENUM – Howard

+0

huh? ........... – HelmiB

Trả lời

4

Tôi tin rằng điều này đang xảy ra với bạn vì TTNaviagtor bị hỏng trên iOS 5. xem https://github.com/facebook/three20/pull/719/files. Bạn đã thử chạy cùng một mã trên iOS 4 với cùng một kết quả chưa?

Đề xuất của tôi với bạn là ngừng sử dụng TTNaviagtor. Bạn vẫn có thể sử dụng thư viện ba20 bằng cách đẩy và bật TTViewController theo phương pháp gốc ios.

Dưới đây là một ví dụ về thay thế TTNaviagtor trong ứng dụng của đại biểu của bạn:

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

sau đó bạn có thể đẩy và pop bất kỳ TTViewController (hoặc lớp con của riêng bạn TTViewController) vào _masterNavController . Cá nhân, tôi nghĩ rằng TTNavigator là một mẫu thiết kế xấu, và táo thiết kế hệ thống định vị của họ trong tư duy khác nhau.

0

tại sao không bước vào mã và kiểm tra xem điều gì đã xảy ra?

Tôi tin rằng các đối tượng được tạo trong TTURLMap objectForURL:query:pattern: bạn có thể đặt điểm ngắt và xem tại sao một điểm mới được tạo thay vì sử dụng lại một đối tượng cũ.

này thi hành objectForURL:query:pattern: với bình luận của tôi

- (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; 
    } 
} 
Các vấn đề liên quan