2013-06-20 26 views
1

我需要做一個按鈕(「繼續」),以打開另一個UiView/Page。我對開發非常陌生。有人可以請走過我嗎?謝謝你們,對我來說幫助很大。在故事板中使用UiActionSheet?

代碼:

- (IBAction)OpenActionSheetButton:(id)sender { 


UIActionSheet *actionsheet = [[UIActionSheet alloc]initWithTitle:@"There is no going back,  are you sure???" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Continue" otherButtonTitles:nil, nil]; 
[actionsheet showInView:self.view]; 
} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
if(buttonIndex == 0) 
{ 
    UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"storyboardViewIdentifier"]; 
    //storyboardViewIdentifier is the ViewController identifier you specify in the storyboard 

    //PUSH 
    [self.navigationController pushViewController:controller animated:YES]; 
    //Modal 
    [self presentViewController:controller animated:YES completion:Nil]; 
} 
} 

這就是我與你的代碼:

- (IBAction)OpenActionSheetButton:(id)sender { 


UIActionSheet *actionsheet = [[UIActionSheet alloc]initWithTitle:@"There is no going back, are you sure???" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Continue" otherButtonTitles:nil, nil]; 
[actionsheet showInView:self.view]; 
} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
if(buttonIndex == 0) 
{ 
    if(buttonIndex == 0) 
     [self performSegueWithIdentifier:@"openView" sender:self]; 
    UIViewController *controller = [self.storyboard 


    instantiateViewControllerWithIdentifier:@"storyboardViewIdentifier"]; 
    //storyboardViewIdentifier is the ViewController identifier you specify in the storyboard 

    //PUSH 
    [self.navigationController pushViewController:controller animated:YES]; 
    //Modal 
    [self presentViewController:controller animated:YES completion:Nil]; 
} 

}

+0

是否顯示uiactionsheet? – ApolloSoftware

+0

是的,只是當我點擊「繼續」時,它明顯強制關閉。 – user212803

+2

爲什麼您需要同時推送視圖控制器和模式顯示視圖控制器?你應該只選擇一個。 –

回答

1

你爲什麼不進行呈現SEGUE帶給你的下一個視圖控制器?去你的故事板,並創建一個指向新的視圖控制器的segue。您需要創建一個模態賽格並將其命名爲獨特。

爲此,將所有必要的視圖控制器添加到故事板,然後右鍵單擊視圖控制器呈現。創建模態segue呈現。

然後從你的代碼中,你可以簡單地說:

if(buttonIndex == 0) 
     [self performSegueWithIdentifier:@"openView" sender:self]; 

要解僱更容易!

[self dismissModalViewControllerAnimated:YES]; 
+0

嗨,感謝您的回覆。好。告訴我,如果我這樣做是正確的:我控制點擊從具有操作表的視圖,並拖動到我想要「繼續」按鈕打開的視圖。我敲了模型,並在右邊的「標識符」框中輸入「YesContinue」作爲名稱。你能解釋一下你的意思嗎?「將所有必要的視圖控制器添加到你的故事板,然後右鍵單擊視圖控制器呈現。創建模態segue呈現。」我需要添加更多的viewcontrollers比我已經有?謝謝,我知道我聽起來很基本,但我是:( – user212803

+0

我更新了我的代碼與你有我在那裏^^ – user212803