2011-01-15 1 views
1

이 문제는 설명하기가 너무 힘들어서 최선을 다할 것입니다.TTNavigation 전달 데이터

여러 사용자 프로필이 있습니다. 나는 그들이 같은 수업에서 모두 다루어지기를 바란다.

TT://User/1 
TT://User/2 

왜지도를 사용자 클래스에 매핑했는지를 매핑 할 수 있습니다.

그 외에도 어떤 사용자 ID를 가져올 지 사용자 클래스에 어떻게 알릴 수 있습니까?

답변

3

먼저 URL을 컨트롤러에 매핑해야합니다. 보기를 표시하기 위해 URL을 호출하기 전에 URL 맵을 설정하려는 경우 AppDelegate에서 일반적으로이 작업을 수행합니다.

  • 항상 와일드 카드 URL의 예에서 시작 TTURLMap
  • 를 통해 컨트롤러에 URL을지도 TTNavigator
  • 의 인스턴스를 생성합니다. * TTWebController (웹 브라우저보기 컨트롤러)와 같은 기본보기 컨트롤러에 매핑하십시오.
  • 기본적으로 URL에는 매개 변수가없는 URL과 매개 변수가있는 URL의 두 가지 유형이 있습니다. 이전의 경우 URL이 호출되면 매핑 된 뷰 컨트롤러의 initWithNibName : bundle : "생성자"가 호출됩니다. 후자의 경우, TTURLMap에서 호출 할 "초기화"메소드를 나타낼 수 있습니다. 아래 예를 참조하십시오.
  • 실제로 openURLAction : 메소드를 통해 URL을 엽니 다.

다음은 코드입니다.

@implementation AppDelegate 

- (void)applicationDidFinishLaunching:(UIApplication *)application { 
    TTNavigator* navigator = [TTNavigator navigator]; 

    TTURLMap* map = navigator.URLMap; 

    // This is the default map. * = wildcard, any URL not registered will be 
    // routed to the TTWebController object at runtime. 
    [map from:@"*" toViewController:[TTWebController class]]; 
    [map from:@"tt://catalog" toViewController:[CatalogController class]]; 
    [map from:@"tt://user/(initWithId:)" 
toViewController:[MyUserViewController class]]; 
    [map from:@"tt://user/(initWithId:)" 
toViewController:[MyUserViewController class]]; 

    if (![navigator restoreViewControllers]) { 
    [navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://catalog"]];  
    } 
} 

// ... 

@end 

둘째,

@implementation MyUserViewController 

- (id) initWithId:(NSNumber *)index { 
    if (self = [super initWithNibName:nibName bundle:nil]) { 
    // Do your initialization here. 

    // Get the index from a singleton data manager containing the "model." 
    } 

    return self; 
} 

@end 

셋째 TTViewController 서브 클래스 앱 어디에서 URL로 이동합니다.

// Navigate to the URL. 
[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"tt://user/1"]];