How can I create an Instance of a Class that I do not inherit from and override functions for it?
I Have I class called GetData and a viewController called SocialViewController.
@interface GetData : NSObject<NSURLConnectionDelegate> and
@interface SocialViewController: UITableViewController<UITableViewDataSource>
Every time I try to create a instance of GetData in my SocialViewController implementation and override the functions it doesn't work and the functions in GetData are executed instead.
How can I create a instance of GetData in SocialViewController when SocialViewController inherits from UITableViewControler and not GetData?
@implementation SocialViewController
GetData myGetData;
- (void)viewDidLoad {
[super viewDidLoad];
myGetData = [GetData alloc];
NSString someString = @"my init string"
[myGetData initWithValue:someString];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//The method that I'm trying to override
}
You need to create a class which is a subclass of GetData
in order to override methods. So more like:
@interface MyGetData : GetData @end
@implementation MyGetData
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//The method that I'm trying to override
}
@end
@implementation SocialViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString someString = @"my init string";
myGetData = [[MyGetData alloc] initWithValue:someString;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.