1. iPhoneの場合
[actionSheet showInView: self.view.window];
2. iPadの場合
[actionSheet showInView: self.view];
上記コードでiPad使用時にActionSheetが表示されるようになるが、iPadの場合、actionSheetを使用する場合は、PopOverとして表示させる必要があると、iPadヒューマン インタフェース ガイドラインに記載されている。つまり、どこをタッチしたことによるactionSheetの表示であるかを明示させる必要がある。
従って、上記2.のコードでは審査時にはRejectされる。
iPadの場合は、UIActionSheetのリファレンスの通り、showFromRectやshowFromBarButtonItem、showFromTabBar、showFromToolbarなど、元となるオブジェクトを指定すること。
1. TableViewCellをタッチしてActionSheetを表示する場合
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPathTableViewCellの上部から少し、矢印が食い込んだ形で、ActionSheetが表示される。
{
UIActionSheet *actionSheet = [[[UIActionSheet alloc]
initWithTitle: @"hoge"
delegate: self
cancelButtonTitle: @"cancel"
destructiveButtonTitle: nil
otherButtonTitles:
@"OK", nil]
autorelease];
CGRect frame = [tableView rectForRowAtIndexPath:indexPath];
CGPoint yOffset = self._detailitemTable.contentOffset;
[actionSheet showFromRect:CGRectMake(frame.origin.x, (frame.origin.y + 15 - yOffset.y), frame.size.width, frame.size.height) inView:self.view animated:YES];
}
2. NavigationBarの右ボタンをタッチしてActionSheetを表示する場合
[actionSheet showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
3. TableViewCellの上に設置したボタン等をタッチしてActionSheetを表示する場合
NSIndexPath *workIndexPath = [NSIndexPath indexPathForRow:3 inSection:0];※上記は、sectionが0、indexPathRowが3のcellに設置された、幅130.0、高さ35.0のボタンに向けてActionSheetを表示する。
UITableViewCell *cell = [self._detailitemTable cellForRowAtIndexPath:workIndexPath];
CGRect rect = cell.frame;
CGPoint offset = self._detailitemTable.contentOffset;
rect.origin.x = rect.origin.x - offset.x;
rect.origin.y = rect.origin.y - offset.y;
[actionSheet showFromRect:CGRectMake(rect.origin.x, rect.origin.y, 130.0, 35.0) inView:self.view animated:YES];
iPad専用アプリでは通常、actionSheetを使用すると、システムでcancelボタンは表示されないようになっている。
なぜならば、PopOverのcancel(または画面を閉じる)操作はPopOverViewの外側をタッチする実装なので、cancelボタンを追加することはこれと矛盾する。
■参考 UIActionSheet Class Reference
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIActionSheet_Class/Reference/Reference.html
http://stackoverflow.com/questions/2676394/how-to-get-rect-size-of-uitableviewcell
http://songofcloud.gluegent.com/2010/04/uitableviewcell.html
【UIActionSheetの最新記事】