2011-01-24 14 views

答えて

8

新しいUIActionSheetインスタンスを割り当てて初期化し、–addButtonWithTitle:を使用してボタンを1つずつ追加します。このメソッドは、ボタンが追加されたインデックスを返します。次に、-setDestructiveButtonIndexを使用して破壊ボタンのインデックスを設定します。ここで

は、(それが赤作り、そして直接など破壊的なボタン設定)1つのボタンを追加し、ブール値useDestructiveButtonYESであれば別のものを追加する例です:

UIActionSheet *sheet = [[UIActionSheet alloc] init]; 
[sheet addButtonWithTitle:@"Button 1"]; 
if (useDestructiveButton) { 
    [sheet setDestructiveButtonIndex:[sheet addButtonWithTitle:@"Button 2"]]; 
} 

は呼び出すことを忘れないでください。適切なshowメソッド。

2
UIActionSheet * as=[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel",@"Cancel") destructiveButtonTitle:nil otherButtonTitles:nil]; 
[as setTag:0]; 
[as addButtonWithTitle:NSLocalizedString(@"First Button",@"First Button")]; 
[as addButtonWithTitle:NSLocalizedString(@"Second Button",@"Second Button")]; 
[as showInView:someController.view]; 
[as autorelease]; 

はまた、あなたの親コントローラがUIActionSheetDelegateプロトコルに準拠していることを覚えておいてください。

関連する問題