UIAlertActionを生成してハンドラで返すことのできる関数を作成することは可能ですか?UIAlertViewController用のUIAlertActionを作成する共通の関数をアプリケーション全体で使用するにはどうすればいいですか?
私はUIAlertActionのコードを複数回書く必要はなく、必要なシナリオごとにUIAlertActionを作成できる単一の関数を作成しようとしています。 ここに私のコードです。
UIAlertAction *actionPast = [self createActionButton:@"Past"];
UIAlertAction *actionFuture = [self createActionButton:@"Future"];
-(UIAlertAction *)createActionButton : (NSString *)title{
UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}];
return action;
}
したがって、任意のUIAlertActionをクリックすると、ハンドラを元に戻して任意のタスクを実行する可能性があります。
質問が不明です。なぜあなたはこれをやろうとしていますか? –
私はUIAlertActionコードをすべてのコントローラに何度も書きたくないだけです。 –
私はシングルトン関数がアプリケーション全体のためにUIAlertActionを作成したいと思っています –