bricklifeのはてなブログ

気軽にブログ書くよ!

iOS 5で挙動が変わったUI系APIまとめ

随時追記。自分で確認していない情報もあります。

addSubveiw: しただけで viewWillAppear: が呼ばれる

viewDidAppear: なども同様。iOS 5以前はメイン以外のコントローラのは呼ばれなかったので、手動で呼ぶようにしていた場合は要注意
http://hmdt.jp/blog/?p=261

※ willRotateToInterfaceOrientation:duration: や didRotateFromInterfaceOrientation: は従来どおりメインのコントローラのしか呼ばれない

parentViewController が nil になる

親のViewControllerを取得するにはiOS 5からできた presentingViewController というプロパティを使う
http://www.comgate.jp/taiatari/archives/529

関連:iOS5でモーダルビューを閉じる

http://iphone-app-developer.seesaa.net/article/230242633.html
→ これは上記の presentingViewController を使って [self.presentingViewController dismissModalViewControllerAnimated:YES]でもOK
http://cocoadays.blogspot.com/2011/10/ios5-uiviewcontrollerparentviewcontroll.html

UIKeyboardWillShowNotification がキーボード変更時にも呼ばれる

iOS 5以前ではキーボードが現れたときだけだった。対応するには通知に登録してあるメソッド内で [[notificatioin.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue:&rect] を使ってキーボードのサイズを取得する。またはiOS 5からできた UIKeyboardWillChangeFrameNotification や UITextInputCurrentInputModeDidChangeNotification を使う
http://d.hatena.ne.jp/k2_k_hei/20111023/1319378195
http://iphone-app-developer.seesaa.net/article/230522433.html

関連:新しく追加された通知があるかどうか調べるには?

http://cocoadays.blogspot.com/2011/11/ios-ios5.html

shouldChangeCharactersInRange や shouldChangeTextInRange で色々

色々あるので以下参照
http://araking56.blog134.fc2.com/blog-entry-176.html

UISegmentedControlのselectedSegmentIndexを変更してもアクションが呼ばれない

iOS 5以前ではselectedSegmentIndexに数値を代入するとUIControlEventValueChangedに関連付けられたアクションが呼ばれたが、iOS 5では呼ばれなくなった。これは今のほうが仕様的に正しいと思うけど、ハマりがちなポイント