尝试设置一个委托方法来获取urlConnection数据 [英] trying to set a delegate method to get urlConnection data

查看:214
本文介绍了尝试设置一个委托方法来获取urlConnection数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在四处走走,我一直在试图使用这个示例,但在委托方法中遇到麻烦。我想弄清楚如何关闭这个。看起来我已经设置正确,但需要最后一步的帮助:

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:

我正在获得 - [ThirdTab apiFinished:]:无法识别的选择器发送到实例。

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

在WebServiceAPI.m的第二行:self.aDelegate = aDelegate给我一个错误:
2)aDelegate隐藏实例变量的本地声明。

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.

谢谢。

这是在我的ThirdTab UITableViewController中:

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

这是WebServiceAPI.h:

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

以下是我遇到问题的WebServiceAPI.m: / p>

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


推荐答案

您的WebService.h声明属性:

Your WebService.h declares a property:

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

您的WebService.m使用不同的属性:

Your WebService.m uses a different property:

self.delegate = aDelegate;

您可以更改要在WebService.h中委托的属性名称,也可以使用当前名称的财产在WebService.m。

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.

这篇关于尝试设置一个委托方法来获取urlConnection数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆