trying to set a delegate method to get urlConnection data

三世轮回 提交于 2019-12-13 03:52:19

问题


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;
 }

回答1:


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.



来源:https://stackoverflow.com/questions/4027406/trying-to-set-a-delegate-method-to-get-urlconnection-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!