2011-11-04 61 views
1

我似乎無法在網上找到此任何位置。我在其中一個視圖中有一個添加按鈕,我已將其連接到名爲addIBAction方法。在我的故事板中,我創建了一個視圖,其中包含一個表單。我也在故事板中爲該視圖分配了一個類。該課程名爲AddItemViewController在iOS 5中以模態方式呈現的當前視圖

我想以模態方式呈現此視圖,然後將該委託設置爲調用AddItemViewController的視圖。但是,我得到的只是一個空的UITableViewController,它顯示出來了。這裏是我試圖使用的代碼:

- (IBAction)add { 
    AddItemViewController *addItem = [[AddItemViewController alloc] init]; 
    addItem.delegate = self; 
    [self presentModalViewController:addItem animated:YES]; 
} 

有什麼我失蹤了嗎?爲什麼它只顯示一個空表而不是我在故事板中設置的視圖控制器?

下面是從AddItemViewController代碼:

@interface AddItemViewController : UITableViewController <UITextFieldDelegate> { 
} 

@property (strong, nonatomic) IBOutlet UITextField *note; 

- (void)save:(id)sender; 
- (void)cancel:(id)sender; 
@end 


@implementation AddItemViewController 
    - (void)viewDidLoad { 

    } 

    - (IBAction)cancel:(id)sender { 
     [self dismissViewControllerAnimated:YES completion:nil]; 
    } 

    - (IBAction)save:(id)sender { 
     DbHandler *db = [[DbHandler alloc] init]; 
     [db executeUpdate:self.note]; 

     [self dismissViewControllerAnimated:YES completion:nil]; 
    } 
@end 
+0

你可以爲AddItemViewController類的代碼? –

+0

添加上面的AddItemViewController代碼 – intargc

回答

1

那麼從UITableViewController中,沒有的UIViewController AddItemViewController繼承,因此它是有道理的,一個UITableViewController被顯示出來。

你應該啓動AddItemViewController這樣的:

AddItemViewController *addItem = [[AddItemViewController alloc] initWithNibName:@"AddItemViewController"];

相關問題