Search code examples
iosobjective-cdelegatesnsurlconnection

No visible @interface for 'UIViewController' declares the selector


This is day 1 of Objective C for me, so please bear with me.

I am trying to allow self (referencing my LoginViewContoller class) to be accessible to my delegate method connectionDidFinishLoading, wherein I take the response and pass it to my returnResponseFromPost method in my LoginViewController.m file.

Currently, in my HTTPUtility.m file, I have a custom initializer. My goal is to assign the LoginViewController's self (that I passed to the HTTPUtility's initWithViewController method) to my property self.viewController, so that I can make the appropriate method call to returnResponseFromPost. However, I am receiving an error, and I'm not sure why:

No visible @interface for 'UIViewController' declares the selector 'returnHtmlFromPost:'

I understand what this message is saying, but I'm confused on a deeper level as to why viewController is being recognized as UIViewController as opposed to what I expected to be LoginViewController.

Here is the relevant code...

In my LoginViewController.h file:

@interface LoginViewController : UIViewController;
...
- (void) returnResponseFromPost:(NSString *)responseString;

In my LoginViewController.m file:

HTTPUtility *httputil = [[HTTPUtility alloc] initWithViewController:self];

In my HTTPUtility.h file:

@class UIViewController;

@interface HTTPUtility : NSObject {
    NSMutableData* responseData;
    UIViewController* viewController;
}

@property (strong, nonatomic) UIViewController* viewController;
@property (strong, nonatomic) NSMutableData *responseData;

- (id) initWithViewController:(UIViewController *)vwController;

In my HTTPUtility.m file:

- (id) init {
    return [self initWithViewController:nil];
}

- (id) initWithViewController:(UIViewController *)vwController {
    self = [super init];
    if (self) {
        responseData = [[NSMutableData alloc] init];
        self.viewController = vwController;
    }
    return self;
}  

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
     NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

     // Here is where the error is thrown...
     [viewController returnResponseFromPost:responseString];
}

At first I figured this was a matter of a forgotten import statement, but I've experimented with that to no avail. I'd really appreciate some help with this so I can understand where I'm going wrong! Thanks.


Solution

  • You typed viewController as a UIViewController when you declared it. You need to type it as a LoginViewController. You also shouldn't be declaring both an ivar and a property. Just declare the property, and delete the two ivars.