1

のボタンの 1 つUIActionSheetUIView. Facebook をアプリに統合しています。ログイン ボタン (FBLoginView) は のサブクラスですUIView。このビューを のボタンとして使用したいUIActionSheet。これは可能ですか?

編集: Facebook 共有をアプリに統合しようとしています。そのために、私は彼らのSDKを使用する必要があります。Facebook にログインするために、UIView のサブクラスとして作成された「FBLoginView」と呼ばれる独自のカスタム ビューを提供します。メモリを割り当てて、このビューを自分のビューに追加するだけです。次に、ビューをクリックすると、sdk で提供されるすべての関数が呼び出され、fb アプリまたは safari が開き、ログインとパスワードなどを求められ、アプリに戻ります。

このボタンを UIActionSheet に配置したいと思います。シートには、ボタンをカスタマイズするオプションが表示されません。オプションがあったとしても、UIView を使用して UIButton を作成するにはどうすればよいですか?

4

2 に答える 2

0

をいじるのは得策ではありませんUIActionSheet

UIActionSheet クラスリファレンスから:

サブクラス化の注意事項

UIActionSheet はサブクラス化するようには設計されていないため、その階層にビューを追加するべきではありません。UIActionSheet API で提供される以上のカスタマイズでシートを表示する必要がある場合は、独自のシートを作成して、presentViewController:animated:completion: でモーダルに表示できます。

かなりの数のアクション シートの置き換えがあります。開始リストについては、https://www.cocoacontrols.com/search?q=uiactionsheetを参照してください。

私の提案は、ハッキングする代わりに、好きな機能を備えたものを見つけることですUIActionSheet.

于 2014-08-17T16:07:57.790 に答える
0

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 クラスはそのまま使用することを意図しており、サブクラス化はサポートしていません。このクラスのビュー階層は非公開であり、変更してはなりません。

于 2014-08-17T15:55:36.147 に答える