ios - iPad App Crashes on Orientation change -
i developing ipad app. allow both landscape , portrait mode. ui fine in portrait mode when alter landscape mode, ui gets messed up. saw posts related , added next code in initwith... in uiview.
[[uidevice currentdevice] begingeneratingdeviceorientationnotifications]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(abc) name:uideviceorientationdidchangenotification object:nil];
my ui working fine in portrait mode after doing this. when alter landscape mode, ui fine. after alter portrait mode, app crashes. read posts on related app crashing got know instruments. enabled zombies , found message beingness sent released object , message coming nsnotificationcenter.
is there else need handle apart registering device ? also, there way in can alter implementation uiview uiviewcontroller , implement methods uiviewcontroller has regarding device orientation ? please allow me know steps need follow in order done. thanks!
where registering notifications? need remove observer when alter orientations (either in prepforsegue or willanimaterotationtointerfaceorientation depending on you've got setup) in order prevent messaging no longer valid object. don't want pile several notifications if registering in viewdidappear/viewwillappear.
remove observer using:
[[nsnotificationcenter defaultcenter] removeobserver:self];//removes notifications object (the way i've used before)
or if want specific, like:
[[nsnotificationcenter defaultcenter] removeobserver:self name:uideviceorientationdidchangenotification object:[uidevice currentdevice];//remove notification
ios objective-c nsnotificationcenter device-orientation
No comments:
Post a Comment