工場裏のアーカイブス

素人によるiPhoneアプリ開発の学習記 あと機械学習とかM5Stackとか

Xcode 5(iOS 7)におけるUIActionSheet利用時の注意点

先日、ついにiOS 7がリリースされ、それと同時にiOS 7向けアプリ開発に対応したXcode 5がリリースされました。さっそくXcode 5を自機に導入し、旧バージョンで作成したあるプロジェクト(UIActionSheetを利用している)をビルドしてみたのですが、そのとき旧バージョンでは全く無かった警告メッセージが表示されることに気がつきました。

そのプロジェクトでは UIPickerView を載せた UIActionSheet を表示して、手軽にアプリ上で選択肢を入力出来るようにしております(※具体的な方法についてはこちらのリンク先などを参照)。このような UIActionSheet を生成する際には、以下のようにボタンが何も表示されないように設定をします。

//Xcode 5以前のバージョンでは、これでも問題はない。
[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

Xcode 5以前のバージョンでは、この書き方で何の問題も起こりませんでした。しかしXcode 5でこの記述をすると、一応動作はしますが下記のような大量の警告メッセージが表示されます。

CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextSetFlatness: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextDrawPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

この警告メッセージが出る背景や詳細についてはまだ理解出来ておりませんが、色々調べた結果、ひとまずXcode 5では以下のように cancelButtonTitle: の引数を nil ではなく @"" に書き換えることで、この警告メッセージが表示されなくなるようです。

//Xcode 5ではこのように記述する(※Xcode 5以前のバージョンでは、余計なボタンが表示される恐れあり)
[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles:nil];

 
 

追記(2013/10/01)

iOS Dev Center から旧バージョンのXcodeをダウンロードすることができ、かつ最新バージョン(Xcode 5)と共存させることが可能であることが分かったので、Xcode 4.6.3を自機に再導入してみました。

そして Xcode 4.6.3 のプロジェクト上で UIActionSheet を、cancelButtonTitle: の引数を nil にする従来の方法で生成しビルドしてみたところ、iPhone 6.1シミュレータ上で実行する際には何の警告も出ませんでした。しかしiOS 7を導入した実機上で実行してみたところ、例の大量の警告が出てしまいました。

Xcode 5では警告が出るのではなくて、iOS 7の環境では警告が出るという理解の方が正しいようです。