2013-01-17 15 views
6

私はストーリーボードを使用しているアプリケーションを持っています。ビューにはAlertViewDialogがあります。手作業でストーリーボードビューを開く

ユーザーが最初のボタン(「はい」)をクリックすると、ストーリーボードで他のビューを開くにはどうすればよいですか?

答えて

10

が、これは助けることができることが私の:

  1. ドラッグはその後での表示では、Identityインスペクタに行く(ショートカット:オプション+りんご+ 3)。
  2. 新しくドラッグされたビューを選択し、タイトルストーリーボードIDの識別インスペクタから一意の名前を付けます。 //基準 enter image description here

SecondViewControllerクラスを作成する(.H & .M)のViewControllerのサブクラスのための画像を見ます。 (YESをクリックしたときに、あなたが言ったように)、アラートビューコードから、その後

は、すべての問題が発生した場合、私に知らせて

SecondViewController *svc =[self.storyboard instantiateViewControllerWithIdentifier:@"vinay"]; 
     [svc setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; 
     [self presentViewController:svc animated:YES completion:nil]; 

の下に言及したコードを貼り付けます。

+0

感謝!できます! –

+0

あなたの歓迎と私の記事を好きに感謝:) –

5

は、ことがありますが、これは役立ちます:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
ClassNameViewController *viewController = (ClassNameViewController *)[storyboard instantiateViewControllerWithIdentifier:@"viewIdentifierOnStoryboard"]; 
[self presentModalViewController:viewController animated:NO]; 
+0

あまりにも悪い、動作しません。何も起こりません... –

+0

あなたのビューに識別子を設定し、同じストーリーボード名を使用しましたか? – Tchelow

+0

ストーリーボードIDを 'eerstekeer'に設定しました。 「ストーリーボードIDを使用する」チェックボックスをオンにして、インポートを開始します。このコードを使用してください: UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@ "MainStoryboard" bundle:nil]; スタートアップ* viewController =(スタートアップ*)[ストーリーボードinstantiateViewControllerWithIdentifier:@ "eerstekeer"]; –

0

あなたがする必要がある最初の事は、これはあなたの@interfaceUIAlertViewDelegateを追加行うUIAlertViewデリゲートを設定されているので、

 @interface myClass : super <UIAlertViewDelegate> 
      // super could be anything like `UIViewController`, etc 
     @end 

のように見え、@implementationにあなたがして

 @implementation myClass 

     ........... Some code 


     - (IBAction)someActionMethod:(id)sender 
     { 
      UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:nil 
                    message:@"Would you like to move on?" 
                   delegate:self 
                 cancelButtonTitle:@"No" 
                 otherButtonTitles:@"Yes", nil]; 
      [myAlertView show]; 
      // [myAlertView release]; Only if you aren't using ARC 
     } 

     - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
     { 
       switch(buttonIndex) { 
        case 1: 
          SecondViewController *svc =[self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"]; 
          [svc setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; 
     // [self presentViewController:svc animated:YES]; // Deprecated in iOS 6.0 
          [self presentViewController:svc animated:YES completion:nil]; // Introduced in iOS 5.0 
          break; 
        default: 
          break; 
       } 
     } 

     @end 
のようなものを追加することができます

ストーリーボードに一意の識別子を設定することを忘れないでください。 .storyboardにアクセスし、IDインスペクタ(3番目のIDを選択)でStoryboard IDを設定することができます。これはinstantiateViewControllerWithIdentifierにあるものと一致する必要がありますので、上記の場合は"secondViewController"となります。それは簡単です。

が完了したら、あなたが上記の実際のiOS 6.0で廃止されましたが、あなたが同じことを行い

 [self dismissModalViewControllerAnimated:YES completion:nil]; 

を使用することができます

 [self dismissModalViewControllerAnimated:YES]; 

を使用する必要があります。このビューを却下することを忘れないでくださいただし、最後に補完ブロックが追加されます。

これが役に立ちます。

関連する問題