问题
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