2013年09月27日

iOS7でUIActionSheetを表示する

iOS7でUIActionSheetを表示しようとすると、従来のコードでは
'NSInvalidArgumentException', reason: 'Sheet can not be presented because the view is not in a window
とコンソールに表示されてアプリがクラッシュする。

修正前
UIActionSheet *actionSheet = [[[UIActionSheet alloc]
initWithTitle: @"Hoge"
delegate: self
cancelButtonTitle: @"Cancel", nil)
destructiveButtonTitle: nil
otherButtonTitles:
@"Done", nil]
autorelease];

CGRect frame = [[UIScreen mainScreen] applicationFrame];
UIView *actionSheetsubView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,frame.size.width,frame.size.height)]autorelease];
[actionSheet showInView: actionSheetsubView];


修正後
UIActionSheet *actionSheet = [[[UIActionSheet alloc]
initWithTitle: @"Hoge"
delegate: self
cancelButtonTitle: @"Cancel", nil)
destructiveButtonTitle: nil
otherButtonTitles:
@"Done", nil]
autorelease];

[actionSheet showInView:[[[[UIApplication sharedApplication] keyWindow] subviews] lastObject]];



参考記事:
http://stackoverflow.com/questions/18932544/nsinvalidargumentexception-reason-sheet-can-not-be-presented-because-the-vi


ラベル:IOS Mac iPAD iPhone apple
posted by mobileDeveloper at 20:07 | Comment(0) | TrackBack(0) | UIActionSheet | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:

認証コード: [必須入力]


※画像の中の文字を半角で入力してください。
※ブログオーナーが承認したコメントのみ表示されます。

この記事へのトラックバック