hachinoBlog

hachinobuのエンジニアライフ

UIActionSheet,UIAlertViewでの注意点

UIActionSheetのボタンを押すとデリゲート先の

  • (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

に飛んでいくが、ここで(NSInteger)buttonIndexを使用してボタンごとの動きを指定する場合は必ず
if (buttonIndex == -1) {
[actionSheet dismissWithClickedButtonIndex:-1 animated:YES];
return;
}
を入れてあげる。
UIActionSheet外を押した場合はbuttonIndexに-1が挿入されるため。

ボタンを押した時に
if (asheet.visible) {
で既にアクションシートが出ている状態か判断してあげないと二重三重に重なってiPadは表示されてしまう。