2013-06-20 8 views
58

他のメニューボタンを使ってこの種類のメニューを作成したいと思います。それを表すデフォルトのViewControllerはありますか?または画像を取得してこれを自分で作成する必要がありますか?UIActionSheetの作成

enter image description here

+3

(コードはこのチュートリアルからです)http://mobile.tutsplus.com/tutorials/iphone/uiactionsheet_uiactionsheetdelegate

は、詳細は、このチュートリアルを見てみましょう。この質問を再開して、更新された回答を追加できるようにするとよいでしょう。 – Suragch

+2

投票を再開してください。 – Stunner

+0

@Suragchあなたは正しいです。他のリンクよりも助かりました。 –

答えて

11

UIActionSheetのドキュメントを見てみましょう。

NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title 
NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles 
NSString *other1 = @"Other Button 1"; 
NSString *other2 = @"Other Button 2"; 
NSString *other3 = @"Other Button 3"; 
NSString *cancelTitle = @"Cancel Button"; 
UIActionSheet *actionSheet = [[UIActionSheet alloc] 
           initWithTitle:actionSheetTitle 
           delegate:self 
           cancelButtonTitle:cancelTitle 
           destructiveButtonTitle:destructiveTitle 
           otherButtonTitles:other1, other2, other3, nil]; 
[actionSheet showInView:self.view]; 
169

UIActionSheetを使用する必要があります。

まず、UIActionSheetDelegateをViewController.hファイルに追加する必要があります。そして、あなたは通話のそれぞれを処理する必要が

UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select Sharing option:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: 
         @"Share on Facebook", 
         @"Share on Twitter", 
         @"Share via E-mail", 
         @"Save to Camera Roll", 
         @"Rate this App", 
         nil]; 
    popup.tag = 1; 
    [popup showInView:self.view]; 

次にあなたがactionsheetを参照することができます。

- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex { 

    switch (popup.tag) { 
    case 1: { 
     switch (buttonIndex) { 
      case 0: 
       [self FBShare]; 
       break; 
      case 1: 
       [self TwitterShare]; 
       break; 
      case 2: 
       [self emailContent]; 
       break; 
      case 3: 
       [self saveContent]; 
       break; 
      case 4: 
       [self rateAppYes]; 
       break; 
      default: 
       break; 
     } 
     break; 
    } 
    default: 
     break; 
} 
} 

これは、それがUIActionSheetと呼ばれたiOS 8.xの https://developer.apple.com/documentation/uikit/uialertcontroller#//apple_ref/occ/cl/UIAlertController

+5

+! (それは良い答えを提供するだけでなく) 'UIActionSheet'と呼んでいる唯一の人だからです。 – rmaddy

+1

私は質問を見て、文字通り私のアプリで作業していた!それは私のコードに由来しています;) – ApolloSoftware

+1

それはまた、UIActionSheetDelegateを追加せずに動作しています..私はどのように知って... – Nepster

5

のために廃止されました:あなたはそうのようなものを作成します。

NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title 
NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles 
NSString *other1 = @"Other Button 1"; 
NSString *other2 = @"Other Button 2"; 
NSString *other3 = @"Other Button 3"; 
NSString *cancelTitle = @"Cancel Button"; 
UIActionSheet *actionSheet = [[UIActionSheet alloc] 
           initWithTitle:actionSheetTitle 
           delegate:self 
           cancelButtonTitle:cancelTitle 
           destructiveButtonTitle:destructiveTitle 
           otherButtonTitles:other1, other2, other3, nil]; 
[actionSheet showInView:self.view]; 

をボタンアクションに応答するUISctionSheetDelegateを実装します。この質問のタイトルと人気が重複したよりもはるかに優れています