Reputation: 495
I have a ViewController in my project that has a class method that uploads a file to a server. It is class method because it will be access by a NSObject
class that handles the image capturing.
However, as it turns out, I cannot access the ViewController itself from the inside of my static function in the original ViewController. I want to do this in order to show a progress HUD that overlays over the ViewController.
Any idea on how to handle this?
The method is defined as such in the header:
+(void)uploadImage:(NSString*)imagePath thumbnailPath:(NSString*)thumbnailPath;
Upvotes: 0
Views: 504
Reputation: 4946
You could also abstract this out a bit by creating a protocol which you can have any object adopt, and pass that in as a dependency;
@protocol MyProtocol
-(id)someData;
@end
@interface MyObjct
+(void)uploadImage:(NSString*)imagePath thumbnailPath:(NSString*)thumbnailPath dataSource:(id<MyProtocol>)data;
@end
This way, it will not matter if its an instance of a UIViewController
or any other object that implements the methods in MyProtocol
.
Upvotes: 1
Reputation: 7419
Here's a couple options:
1) Make the method an instance method, and have the NSObject call it on your specific instance of the View Controller.
2) Post a notification in the class method and have your view controller instance subscribe to it.
Upvotes: 1