subclassing initWithFileURL of an UIDocument

风格不统一 提交于 2019-12-25 09:08:54

问题


I'm trying to overwrite the initWithFileURL of an UIDocument as I need to call some custom methods once an UIDocument is initialised.

I thought this may be a good idea:

-(id)initWithFileURL:(NSURL *)url {
        self = [super initWithFileURL:url];
        // do some custom stuff
        return self;
}

Is there anything else I need to do if I overwrite this? I have the feeling that I need to check for NIL or something. Where do you usually look if you need to overwrite a method with something custom? I was only able (via jump to definition when right clicking UIDocument) to see this:

    #pragma mark *** Initialization ***

// The designated initializer. Passing an empty URL will cause this method to throw an NSInvalidArgumentException.
- (id)initWithFileURL:(NSURL *)url;

回答1:


You should probably be doing this.

-(id)initWithFileURL:(NSURL *)url {
    self = [super initWithFileURL:url];

    if(self) {

      // Your custom stuff here

   }

    return self;
}


来源:https://stackoverflow.com/questions/11072360/subclassing-initwithfileurl-of-an-uidocument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!