views:

26

answers:

1

I've been going around and around, I've been trying to use this example but running into trouble in the delegate method. I'm trying to figure out how to close this out. Looks like I've got a lot set correctly but need help on final step:

I'm getting a -[ThirdTab apiFinished:]: unrecognized selector sent to instance.

On line two of the WebServiceAPI.m : the self.aDelegate =aDelegate is giving me an error: 2) Local declaration of aDelegate hides instance variable.

This is my first go around with using delegates like this an can't figure out this error.

Thanks.

This is in my ThirdTab UITableViewController:

 -(void)viewDidLoad {
      [super viewDidLoad];
      WebServiceAPI *api = [[WebServiceAPI alloc] init];;   
      api.delegate =self;
          [api DataRequest:data3 delegate:self];

  // this is where I'm trying to connect data3 to my tableview.
        self.tableDataSource3 = [data3 objectForKey:@"Rows"];
            self.webApi = api;
        [api release];

This is the WebServiceAPI.h:

#import <UIKit/UIKit.h>

@class WebServiceAPI;
@protocol WebServiceAPIDelegate;

@interface WebServiceAPI : NSObject
{ 
    id<WebServiceAPIDelegate>aDelegate;
    NSDictionary *data3;
    NSArray *rowsArrayFamily;
    NSMutableData *receivedData;
    NSString *jsonreturnFF;


 }
 @property (nonatomic, assign) id<WebServiceAPIDelegate>aDelegate;
 @property (nonatomic, retain) NSDictionary *data3;
 @property (retain,nonatomic) NSArray *rowsArrayFamily;
 @property (nonatomic, retain) NSMutableData *receivedData;
 @property (nonatomic, retain) NSString *jsonreturnFF;

 - (void) DataRequest: (id) aDelegate;
 @end

 @protocol WebServiceAPIDelegate
 @required
   -(void)apiFinished:(WebServiceAPI*)api;
   -(void)api:(WebServiceAPI*)api failedWithError:(NSError*)error;
  @end

Here is the WebServiceAPI.m where I'm having the issue:

- (void) DataRequest:data3 delegate:(id) aDelegate; {
      self.aDelegate = aDelegate;

        NSUserDefaults *defaultsF = [NSUserDefaults standardUserDefaults];
        NSString *useridFF = [defaultsF objectForKey:kUseridKey];

    NSString *urlstrF = [[NSString alloc] initWithFormat:@"http://www.~.php?userid=%@",useridFF];
    NSURLRequest *req3 =[NSURLRequest requestWithURL:[NSURL URLWithString:urlstrF]];
    NSURLConnection *conn3 = [[NSURLConnection alloc] initWithRequest:req3 delegate:self];

    NSMutableData *data =[[NSMutableData alloc] init];
    self.receivedData = data;   
 // self.connection = conn3;
 }
A: 

Your WebService.h declares a property:

@property (nonatomic, assign) id<WebServiceAPIDelegate>aDelegate;

Your WebService.m uses a different property:

self.delegate = aDelegate;

You can either change the name of the property to delegate in WebService.h, or use the current name of the property in WebService.m.

GregInYEG
I'm confused (shocker), I thought those were the same, If I do this in .m: self.delegate = id<WebServiceAPIDelegate>aDelegate; or if I do this in .h: id aDelegate;
Michael Robinson
I'm confused (shocker), I thought those were the same, I thought I needed the delegate to be named id<WebServiceAPIDelegate>aDelegate. I synthesize the aDelegate and it doesn't have a problem. but it seems that it's the self.delegate this is at issue. maieking the 2nd line "self.delegate = id<WebServiceAPIDelegate>aDelegate;" asks for an expression before id.
Michael Robinson
Yes, changing self.delegate = aDelegate; to self.aDelegate = aDelegate; is one way to fix the problem.
GregInYEG
Thanks. I'm trying to figure out how to close this out now. Should I make a new question?
Michael Robinson
If you consider this question answered, normally you would accept it (if the answer was helpful to you) and post another question if you have another. See the FAQ, particularly "How do I ask questions here?" - http://stackoverflow.com/faq
GregInYEG
I thought so, just tired.
Michael Robinson
Michael, glad to hear you have it solved. The reason I added "aDelegate" in the .m file is that that makes it a *local* variable in that method. If you called it "delegate" there as well, you'd get compiler warnings about how the local variable hides the scope of the class instance variable...
phooze