2012-03-08 3 views
2

私はiPadのアプリのために(UIActionSheetに基づく)ShareKit SHKActionSheetを使用しています:iPad UIActionSheetを外側にタップすると、UIActionSheetの状態になりますか?

SHKItem *item = [SHKItem URL:url title:@""]; 
actionSheet = [SHKActionSheet actionSheetForItem:item]; 
[actionSheet showFromToolbar:self.navigationController.toolbar]; 

私はactionSheetがビューにあるかどうかに応じて、いくつかのアクションを実行します。問題は、ユーザーがactionSheetの外側をタップしてビューから外すと(iPadのデフォルトの動作)、actionSheetはもはや有効なSHKActionSheetを指し示すこともなく、nil値も持たないということです。どのように私はそのような却下をテストすることができますか?

答えて

2

UIActionSheetクラスは、visibleプロパティを持っています。アクションシートが表示されている場合はYES、そうでない場合はNOを返します。それは、それが解雇されたかどうかを知ることができるはずです。

UIActionSheetDelegateの方法を実装して、解読またはキャンセルされたタイミングをactionSheetCancel:および/またはactionSheet:didDismissWithButtonIndex:とすることもできます。

EDIT:

お使いのコントローラのインタフェース宣言(.H)に示すようにしてください、あなたのUIActionSheetのデリゲートの呼び出しを受けるようにしてくださいするには、次の

@interface YourViewController : UIViewController<UIActionSheetDelegate> 

@end 

次に、コントローラの実装に(.M):

- (void)actionSheetCancel:(UIActionSheet *)actionSheet { 

    NSLog(@"action sheet is about to be cancelled"); 
} 

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { 
    NSLog(@"action sheet was dismissed"); 
} 

EDIT 2:

私はちょうどSHKActionSheetクラスのコードを見てきましたが、それはactionSheetCancel:メソッドを実装していないことが判明しています。その理由は受信していません。あなたはactionSheetCancel:方法を通知することにしたい場合は、単にSHKActionSheet.mファイルにこれを追加し、

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated 
{ 
    // Sharers 
    if (buttonIndex >= 0 && buttonIndex < sharers.count) 
    { 
     [NSClassFromString([sharers objectAtIndex:buttonIndex]) performSelector:@selector(shareItem:) withObject:item]; 
    } 

    // More 
    else if (buttonIndex == sharers.count) 
    { 
     SHKShareMenu *shareMenu = [[SHKCustomShareMenu alloc] initWithStyle:UITableViewStyleGrouped]; 
     shareMenu.item = item; 
     [[SHK currentHelper] showViewController:shareMenu]; 
     [shareMenu release]; 
    } 

    [super dismissWithClickedButtonIndex:buttonIndex animated:animated]; 
} 

:それは、しかし、actionSheet:didDismissWithButtonIndex:メソッドを実装してい

- (void)actionSheetCancel:(UIActionSheet *)actionSheet { 

    [super actionSheetCancel:actionSheet]; 
} 

あなたの中にデリゲートメソッドその後、コントローラは正常に呼び出されます:)

UIActionSheet Class Reference

UIActionSheetDelegate Protocol Reference

+0

問題は、私がactionSheet.visibleを終了した後にテストするとアプリケーションがクラッシュすることです。 –

+0

その場合は、私が言及したデリゲートメソッドを実装してみてください。アクションシートのデリゲートプロパティを設定していることを確認してください: 'actionSheet.delegate = self;' – Mutix

+0

私の設定では以下を行います:\t SHKActionSheet * as [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@ "Share") delegate:自己 cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; しかし、デリゲートの行は、自己がタイプUIActionSheetDelegateではないという警告を表示しています。私は、これが代表者の設立を止めていると思う。 –

関連する問題