2010-02-24 104 views
4

我發現這個代碼顯示模式的看法:呈現視圖控制器模態 - iPad的

- (void)add:(id)sender { 
    // Create the root view controller for the navigation controller 
    // The new view controller configures a Cancel and Done button for the 
    // navigation bar. 
    RecipeAddViewController *addController = [[RecipeAddViewController alloc] 
         initWithNibName:@"RecipeAddView" bundle:nil]; 
    addController.delegate = self; 

    // Create the navigation controller and present it modally. 
    UINavigationController *navigationController = [[UINavigationController alloc] 
          initWithRootViewController:addController]; 
    [self presentModalViewController:navigationController animated:YES]; 


    // The navigation controller is now owned by the current view controller 
    // and the root view controller is owned by the navigation controller, 
    // so both objects should be released to prevent over-retention. 
    [navigationController release]; 
    [addController release]; 
} 

我的問題是如何執行這個代碼(我將其放置在一個buttonPress方法)

我是否需要在我的頭文件中定義任何東西?讓我困惑的一點是,蘋果提供這個,沒有頭文件,所以我不能告訴如果有什麼應該在那裏?

的代碼是指RecipieAddViewController我該怎麼repleace這跟「的UIViewController」?

作爲代表在頭文件中放什麼?我需要在其他地方設置嗎?像有財產?

還有什麼我需要做一次我在buttonPress方法copid這段代碼,使其工作?

感謝和抱歉的所有問題。

回答

4

我的問題是如何執行這個代碼(我將其放置在一個buttonPress方法)

定義方法爲IBAction-(IBAction)add:(id)sender並在界面生成器綁定按鈕的touch up inside事件發送到視圖控制器對象的動作插座add:

我需要在我的頭文件來定義什麼?讓我困惑的一點是,蘋果提供這個,沒有頭文件,所以我不能告訴如果有什麼應該在那裏?

沒有。所有這些東西需要的是UIKit.h您通常需要更改您的標題以添加方法,添加實例變量或包含自定義類。但是,爲了使用該類,您可能需要在某處(在您的頭文件或您的實現文件中)使用#import RecipeAddViewController.h。對於您想要在其他文件中使用的任何自定義類,這都是正確的。

的代碼是指RecipieAddViewController我該怎麼repleace這跟「的UIViewController」?

將其替換爲您要推送的視圖控制器類。 UIViewController本身很少有用的裸體。它是分類的。因此,您創建一個繼承自UIViewController的新類,將其導入標題,創建並實例化它,然後將其推送到導航控制器上。

+0

非常感謝,您的回覆非常好,清除了很多:) – Dave 2010-02-25 01:45:12

相關問題