Xcode 7 + iOS 9 での対応方法については、著者のWebサイトにて情報が公開されておりますので、下記のURLをご確認ください。
http://www.rk-k.com/archives/2449
対象となるページ |
P.183 |
183ページの11行目から15行目(空白行も含む)に誤りがありました。お詫びして訂正させていただきます。
訂正は次の2箇所になります。
・「alert = ~」の前に 「UIAlertView *alert;」が抜けている
・14行目の「cancelButtontitle」は正しくは「cancelButtonTitle」(TitleのTは大文字)
正しいコードは次のようになります。
====
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:@"Time is Up"
message:msg
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
====
対象となるページ |
P.171-186 |
第8講座のLesson 24で解説している「UIAlertView」クラスがiOS 8では非推奨という扱いになり、正しく動作しなくなりました。
iOS 8では「UIAlertController」クラスという新しいクラスを使う必要があります。
P.182からP.183に掲載されている「countDown:」メソッドを次のように変更することで、iOS 7及びiOS 8のどちらでもアラートが表示されるようになります。
====
// タイマーで実行する処理 - (void)countDown:(NSTimer *)timer { // 現在の日時を求める NSDate *now = [NSDate date]; // 残り時間を計算する NSTimeInterval t = [self.gameEndDate timeIntervalSinceDate:now]; // 残り時間が0未満(つまり過ぎている)ときは0とする if (t < 0.0) { t = 0.0; } // 分を求める NSInteger m = t / 60; // 秒を求める NSInteger s = (NSInteger)t % 60; // 文字列にする NSString *str = [NSString stringWithFormat:@"%d:%02d", m, s]; // ラベルにセット self.timeLabel.text = str; // 制限時間がきたら、タイマーを止めて、アラートを表示する if (t == 0.0) { // タイマーを停止する [self.countDownTimer invalidate]; // メッセージを作る NSString *msg; msg = [NSString stringWithFormat:@"Score is %d", self.score]; // iOS 8ならUIAlertControllerが使えるので、その判定を行う if (NSClassFromString(@"UIAlertController")) { UIAlertController *alert; alert = [UIAlertController alertControllerWithTitle:@"Time is Up" message:msg preferredStyle:UIAlertControllerStyleAlert]; // OKボタンを作る UIAlertAction *okAction; okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // OKボタンがタップされたときの処理 // モーダル表示を閉じる [self dismissViewControllerAnimated:YES completion:NULL]; }]; [alert addAction:okAction]; // 表示する [self presentViewController:alert animated:YES completion:nil]; } else { // iOS 8未満なので、UIAlertViewを使う // アラートを作る UIAlertView *alert; alert = [[UIAlertView alloc] initWithTitle:@"Time is Up" // タイトル message:msg // 本文 delegate:nil cancelButtonTitle:@"OK" // ボタンのタイトル otherButtonTitles:nil]; // アラートのデリゲートに設定する alert.delegate = self; // アラートを表示する [alert show]; } } }====
対象となるページ |
P.231-232 |
p.231とp.232のコードのファイル名が逆になっておりました。お詫びして訂正させていただきます。
正しくは、
p.231が「MyGameView.h」
p.232が「MyGameView.m 」
となります。