Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

iphone - trying to set a delegate method to get urlConnection data

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;
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...