I want to override my MYViewController : UIViewController
's setView:
method, such that, I do not allow some one to set view
's property to nil
.
-(void)setView:(UIView*)view {
if (view == nil)
//ignore - make no change
else
//default performance
}
How can I do this?
答案 0 :(得分:2)
仅在您需要默认行为时调用超类才能完成工作:
-(void)setView:(UIView*)view {
if (view == nil) {
//ignore - make no change
}
else {
//default performance
[super setView:view];
}
}
答案 1 :(得分:0)
@synthesize view = _view;
-(void)setView:(UIView*)view {
if (view)
_view = view;
}
可以这么简单地完成。如果view
不是nil,请设置变量。