はい、OHActionSheet
の私のgithubを参照してください。
ブロックを使用して実装されているため、ソースコード内のターゲット/アクションコードを追放しなくても使用できます。ソースコード内のすべてが同じ場所にあるという大きな利点は、あなたが同じコントローラにしたいと、あなたはできるだけ多くOHActionSheets
を使用することができることを
NSURL* anURL = ... // some URL (this is only as an example on using out-of-scope variables in blocks)
[OHActionSheet showSheetInView:yourView
title:@"Open this URL?"
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:[NSArray arrayWithObjects:@"Open",@"Bookmark",nil]
completion:^(OHActionSheet* sheet,NSInteger buttonIndex) {
if (buttonIndex == sheet.cancelButtonIndex) {
NSLog(@"You cancelled");
} else {
NSLog(@"You choosed button %d",buttonIndex);
switch (buttonIndex-sheet.firstOtherButtonIndex) {
case 0: // Open
// here you can access the anURL variable even if this code is executed asynchrously, thanks to the magic of blocks!
[[UIApplication sharedApplication] openURL:anURL];
break;
case 1: // Bookmark
default:
// Here you can even embed another OHAlertView for example
[OHAlertView showAlertWithTitle:@"Wooops"
message:@"This feature is not available yet, sorry!"
cancelButton:@"Damn"
otherButtons:nil
onButtonTapped:nil]; // no need for a completion block here
break;
} // switch
}
}];
[EDIT]詳細および使用例を追加するための編集のサンプルコードを
それはよさそうだが、あなたはまだ定義する必要がありますボタンのタイトルの配列、インデックスに基づいたものを取得し、それらをセレクションに変換しますあなたがその行動を渡したければ、私は 'UIButton'のようなものを望んでいました。タイトル、セレクター、ターゲットを一度に定義するだけでした。 – zekel
ブロックアプローチについて私が気に入っていることの1つは、同じUIBarButtonItemで後続のアクションシートを簡単に表示できることです。 (通常のUIActionSheetでこれを行う良い方法はわかりません) – zekel
(私がアクションを渡す理由は、それらがすべて応答する複数のView Controllerで使用するアクションシートを持つことです) – zekel