StackOverflow の別のユーザーからこれを見つけました。私がしたように、役に立つかもしれません。
UIActionSheet に UIView を subView として追加する
頑張ってください。他の解決策が見つかったらお知らせください:)
更新: iOS 8 以降では廃止されているため、UIACtionSheet には近づきません。今すぐ UIAlertController を使用する必要があります。私は次のようなものを使用します:
UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Connection Method"
message:@"Select Connection Method"
preferredStyle:UIAlertControllerStyleActionSheet];
//These will essentially be the buttons that we used to create for UIActionSheet. They are created pretty much the same way as how they used to,
//but you have to declare their corresponding action here too.
UIAlertAction* firstAction = [UIAlertAction actionWithTitle:@"Title1"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
declaredVariable = NO;
[alert dismissViewControllerAnimated:NO completion:nil];
[self doSomethingHereOrExecuteTheFunctionYouNeed];
}];
UIAlertAction* secondAction = [UIAlertAction actionWithTitle:@"Title2 and so on"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
BOOL newVarable = YES;
[alert dismissViewControllerAnimated:NO completion:nil];
[self followAlertControllerChoice];
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel button"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
//Add buttons ("Actions") here
[alert addAction:firstAction];
[alert addAction:secondAction];
[alert addAction:cancel];
//Finally, present your alertcontroller
[self presentViewController:alert animated:YES completion:nil];
私の知る限り、テキストフィールドのみをアラートコントローラーに追加できます。次のようにできます。
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Enter your text here";
textField.textAlignment = NSTextAlignmentLeft;
//そうそう }];
どうやら、Apple は UIAlertController をサブクラス化することを望んでいないようです。
UIAlertController クラスはそのまま使用することを意図しており、サブクラス化はサポートしていません。このクラスのビュー階層は非公開であり、変更してはなりません。