2014-04-02 42 views
0

好吧,我使用導航控制器爲iPhone創建應用程序,基本上我需要讓我的addviewcontroller知道用戶在addsettingsviewcontroller上選擇了什麼。所以當用戶點擊保存按鈕時,它會打開addviewcontroller,當它打開時,它需要檢查在前一個視圖中選擇了什麼值。我可以讓它爲我做所有這些,但唯一的問題是,當按下保存按鈕並且加載導航欄不再存在時,用戶將無法按下後退按鈕,並且視圖的標題不顯示。 這是我的storyboard的圖片。如何在導航控制器中將數據從一個視圖傳遞到另一個視圖

+0

分享一些代碼,請。 – Rashad

回答

0

如果您正在使用故事板,讓它按照您在其中指定的方式處理您的推動或模態。不要使用擾亂流的代碼來破壞它。

聲明此在AddViewController.h

@property (nonatomic, strong) NSNumber *status; 

然後,在你AddSettingsViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([segue.identifier isEqualToString:@"Add"]) 
    { 
     AddViewController *addViewController = segue.destinationViewController; 
     addViewController.status = Selected_Status; 
    } 
} 

SELECTED_STATUS可以是這樣的:

[NSNumber numberWithInteger:self.levelSegmentedControl.selectedSegmentIndex]; 
+0

這工作!非常感謝我一直在爲此連續3天研究這個問題! – adouglsh9

1

試試這個

Addviewcontroller *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"addView"]; 

controller.status = easy; // select as enum of easy, medium, hard 
[self.navigationController pushViewController:controller animated:YES]; 

希望這可以幫助你!

相關問題