Vì một lý do nào đó bạn phải reshow lại UIPopoverController ví dụ như bạn phải canh giữa màn hình, khi đó bạn cần phải đăng ký lại các notification nếu có cho UIPopoverController này. Nếu không sau khi reshow thì UIPopoverController không nhận notification nữa.
Ví dụ bạn muốn điều chỉnh lại kích thước của UIPopoverController mỗi khi bàn phím hiện ra chúng ta phải đăng ký nhận notification UIKeyboardWillShowNotification như sau:
//MyPopoverViewCtrl.h
@interface MyPopoverViewCtrl:UIPopoverController
-(void) reshow;
@end
//MyPopoverViewCtrl.m
@implementation MyPopoverViewCtrl
-(void) registerKeyboardEvent {
[ [NSNotificationCenter defaultCenter] addObserver:self select:@selector(doSomething:) name:UIKeyboardWillShowNotification object:nil];
}
-(void) unregisterKeyboardEvent{
[ [NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
}
- (id)initWithContentViewController:(UIViewController *)viewController
self = [super initWithContentViewController:viewController];
if(self){
[self registerKeyboardEvents];
}
return self;
}
-(void) dealloc{
[self unregisterKeyboardEvent];
[super dealloc];
}
-(void) reshow{
[self unregisterKeyboardEvent];
//do reshow
[self registerKeyboardEvent];
}
-(void) doSomething:(NSNotification*)noti{
//Do what you want.
}
@end
Không có nhận xét nào:
Đăng nhận xét