ASIHTTPRequest requestFinished内部子类永远不会调用

时间:2014-09-24 11:44:06

标签: ios objective-c xcode asihttprequest

UIViewController startHome )使用子类方法( invioDati )向站点发送用户名和密码。 ASIHTTPRequest课程的发送工作。 但是,我需要在 startHome 中知道异步何时完成以及失败或成功。

使用我的代码,requestFinished永远不会打电话。

如果我将所有 invioDati 代码放在 starHome 中,那就很好了。

我从 starthome.m 中删除了无用的代码,就像UITextField add一样。

startHome.h

#import <UIKit/UIKit.h>

@interface startHome : UIViewController <UITextFieldDelegate>
{
UITextField  *regUtente, *regPassword;
}

-(void)inviaRegistrazione;

@end

startHome.m

#import "startHome.h"
#import "invioDati.h"

- (void)viewDidLoad
{
[super viewDidLoad];

--CODE CUT--

[invioDati invioDatiRegistrazione:regUtente.text password:regPassword.text];  
}

invioDati.h

#import <Foundation/Foundation.h>
#import "ASIHTTPRequest.h"

@interface invioDati : NSObject <ASIHTTPRequestDelegate>


+(void)invioDatiRegistrazione: (NSString *)utente password:(NSString *)password;

@end

invioDati.m

#import "invioDati.h"
#import "ASIFormDataRequest.h"
#import "ASIHTTPRequest.h"

@implementation invioDati

+(void)invioDatiRegistrazione: (NSString *)utente password:(NSString *)password
{


NSURL *url = [NSURL URLWithString:@"http://www.siteaddress.com/page.php"];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request setPostValue:utente forKey:@"utente"];
[request setPostValue:password forKey:@"password"];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(requestFinished:)];
[request startAsynchronous];
 }

- (void)requestFinished:(ASIHTTPRequest *)request {
// this is called if the request is successful
NSLog(@"registerFinished %@",[request responseString]);
}

- (void)requestFailed:(ASIHTTPRequest *)request {
// this is called if the request fails
NSLog(@"registerFailed %@", [request error]);
}

- (void)requestStarted:(ASIHTTPRequest *)request{
// this is called if the request start
NSLog(@"request started");
}
@end

0 个答案:

没有答案