0

メインのViewControllerがあり、ボタンをタップするとアクションシートが表示されます。そこでタップしたオプションの1つで、アクションシートを表示したいと思います。しかし、すべての検索にもかかわらず、私はそれを理解できないようです。

私は次のコードを持っています:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];

    if ([buttonTitle isEqualToString:@"Text"]) {
        AddTextViewController *addTextViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"addTextViewController"];        
    }

ビューコントローラをインスタンス化したので、どうしたらよいかわかりません。

4

1 に答える 1

0

インスタンス化した直後にこの行を追加します。

if ([buttonTitle isEqualToString:@"Text"]) {
    AddTextViewController *addTextViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"addTextViewController"];        
    [self presentViewController:addTextViewController animated:YES completion:nil];
}

ノート

ストーリーボードでビューを表示するカスタムセグエを作成することもできます。インスタンス化して表示する代わりに、カスタムセグエを実行するだけです。どちらも同じように機能します。

ストーリーボード方式

まずストーリーボードでセグエをクリックし、次に情報パネルで識別子を指定します。

ストーリーボードセグエ設定

次に、コードをこれに置き換えることができます。これにより、ストーリーボードからセグエがトリガーされます。

if ([buttonTitle isEqualToString:@"Text"]) {
    [self performSegueWithIdentifier:@"infoSegue" sender:self];
}
于 2013-03-18T14:08:38.727 に答える