2011-04-07 4 views
0

私のアプリケーションでUIBarButtonItemから正常に呼び出せるUIActionSheetがあります。しかし、UIActionSheetのボタンをクリックすると、呼び出すメソッドが呼び出されず、UIActionSheetが消えてしまいます。私MapViewController.mファイルでUIActionSheetからボタンを押した後にメソッドを呼び出すときに助けが必要

@interface MapViewController : UIViewController<MKMapViewDelegate, UIActionSheetDelegate>{ 

::私は間違っているつもりどこ

-(IBAction)showActionSheet { 
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Share your favourite restaurant with your friends" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"EMail",@"Facebook",@"Twitter",nil]; 
[actionSheet showInView:self.view]; 
[actionSheet release]; 
} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
if(buttonIndex == 0) 
    NSLog(@"You chose email!"); 
if(buttonIndex == 1) 
    NSLog(@"You chose facebook!"); 
if(buttonIndex == 2) 
    NSLog(@"You chose twitter!"); 
} 

誰もが見ることができる私のMapViewController.hファイルで

:私の関連するコードは次のようになりますか?個人的には、UIActionSheetDelegateインターフェイスの実装方法と関連があるかもしれません。

+0

感謝を実装して確認する必要があります。あなたはすべて正しかった!その監督を指摘してくれてありがとう。世話をする。 – syedfa

答えて

0
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Share your favourite restaurant with your friends" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"EMail",@"Facebook",@"Twitter",nil]; 

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Share your favourite restaurant with your friends" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"EMail",@"Facebook",@"Twitter",nil]; 

ことも、あなたの.hファイルはあなたの迅速な回答のすべてのために非常に多くのUIActionSheetDelegateプロトコル

0

あなたが代理人としてnilを渡しているが、デリゲートは、あなたのビューコントローラであるので、自己を渡す:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Share your favourite restaurant with your friends" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"EMail",@"Facebook",@"Twitter",nil]; 
0

、あなたがデリゲートを設定することを忘れても、あなたのコード内で以下

actionSheet.delegate = self ; 
を追加することができます

ドキュメントから... レシーバのデリゲートまたはデリゲートがない場合はnil。

@property(nonatomic, assign) id<UIActionSheetDelegate> delegate 
関連する問題