2011-02-24 51 views
2

我開始與Three20庫工作,創建使用下面的代碼UIButtonThree20簡單的導航

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Add New" 
                      style:UIBarButtonItemStyleBordered 
                      target:@"tt://samples/new" 
                      action:nil] autorelease]; 

當用戶觸摸按鈕,我想推NewSampleViewController一個實例到導航。我已經加入我的應用程序委託的-didFinishLaunchingWithOptions方法如下:

[map from:@"tt://samples/new" toViewController:[NewSampleViewController class]]; 

目前的情況是,當按鈕被觸摸時,什麼都不會發生在所有。設備上沒有任何反應,並且在控制檯中看不到任何日誌記錄。

我做錯了什麼或錯過了這裏?

謝謝!

回答

3

除非有神奇的東西我還沒有發現,我認爲你沒有正確地連接你的按鈕代表團。看起來你已經告訴按鈕字符串@「tt:// samples/new」是接收按下事件的對象,並且你希望它不發送消息(不調用方法/無)。

創建與按鈕視圖控制器,像這樣的方法:

- (void)addButtonPressed:(id)sender{ 
    TTURLAction *urlAction = [TTURLAction actionWithURLPath:@"tt://samples/new"]; 
    [[TTNavigator navigator] openURLAction:urlAction]; 
} 

然後用此取代你的按鈕初始化:

self.navigationItem.rightBarButtonItem = 
      [[[UIBarButtonItem alloc] initWithTitle:@"Add New" 
              style:UIBarButtonItemStyleBordered 
              target:self 
              action:@selector(addButtonPressed:)] 
      autorelease]; 

這將調用TTNavigator單個實例打開使用所提供的字符串路徑創建的操作。該按鈕需要由按鈕代理和自己處理,您的視圖控制器完全適用於此。處理程序方法然後導致使用路徑的three2導航。如果你的appDelegate中有正確的接線,three20將創建並推送你映射的視圖控制器。 希望有所幫助。

0

這可能會起作用,我用它將視圖推到導航控制器上。給了一個動作的導航欄按鈕,那麼下面的動作:

-(IBAction)navigationRightBarButton:(id)sender{ 

    [[TTNavigator navigator] openURLAction: 
    [TTURLAction actionWithURLPath:@"tt://samples/new"]]; // goes tot he ttLauncher class 
} 

那麼這將推動以正確的URL路徑希望這有助於。

2

該解決方案通過Levous的工作,但你可以通過使用魔術Three20 openURLFromButton:選擇器而不是實現自己的。試試這個:

self.navigationItem.rightBarButtonItem = 
[[[UIBarButtonItem alloc] initWithTitle:@"Add New" 
            style:UIBarButtonItemStyleBordered 
           target:@"tt://samples/new" 
           action:@selector(openURLFromButton:)] autorelease]; 

如果你想知道爲什麼這個工程結算:

Three20/src目錄/ Three20UI /源/ UINSStringAdditions.m。

簡而言之,Three20在NSString中添加了openUrlFromButton方法,該方法調用TTNavigator openURLAction。

注意: 此解決方案將無法正常工作,因爲發件人必須是UIBiew類型,而UIBarButton不是。它在v1.02之前工作。現在您需要使用OpenURL自己實現選擇器。傑夫(Three20大老闆)在拉請求中對此發表了評論463:https://github.com/facebook/three20/pull/463