Override UIViewController's view property

时间:2015-04-23 05:31:43

标签: ios objective-c iphone uiviewcontroller

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?

2 个答案:

答案 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,请设置变量。