RestKit iOS:简单的请求错误

我是iOS开发的新手,目前我正在用xCode 4.2testingRestKit 0.9.3 for iOS,我遇到了一些简单的get请求的问题。

我遵循这个教程: https : //github.com/RestKit/RestKit/wiki/Tutorial-%3A-Introduction-to-RestKit

我尝试在TouchUpInsideUIButton上发送一个简单的获取请求到我的web服务。

但是我收到一个“EXC_BAD_ACCESS”: [6373:fb03] *** -[DataAccess respondsToSelector:]: message sent to deallocated instance 0x8275160

应用程序停在RKRequest.m文件的这一行:

 if ([self.delegate respondsToSelector:@selector(requestDidStartLoad:)]) { [self.delegate requestDidStartLoad:self]; } 

我的代码:

MyViewController.m:

 - (IBAction)myAction:(id)sender { DataAccess *data = [DataAccess alloc]; [data sendRequests]; } 

DataAccess.m:

 @implementation DataAccess -(void)sendRequests { [RKClient clientWithBaseURL:SERVER_URL username:SERVER_USERNAME password:SERVER_PASSWORD]; [[RKClient sharedClient] get:@"/myDistantAction" delegate:self]; } #pragma mark - Delegate -(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response { if ([response isOK]) { NSLog(@"Retrieved : %@", [response bodyAsString]); } } @end 

我在互联网上search,但我没有find解决scheme

有人可以帮助我吗?

谢谢,

这可能是一个解决scheme。 我改变你的代码使用单身。 我认为问题是当callback函数被调用,因为他不能再访问实例。

DataAccess.m:

 @implementation DataAccess static singleton *DataAccess= nil; + (DataAccess*)getInstance { if (singleton == nil) { singleton = [[DataAccess alloc] init]; } return singleton; } -(void)sendRequests { [RKClient clientWithBaseURL:SERVER_URL username:SERVER_USERNAME password:SERVER_PASSWORD]; [[RKClient sharedClient] get:@"/myDistantAction" delegate:self]; } #pragma mark - Delegate -(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response { if ([response isOK]) { NSLog(@"Retrieved : %@", [response bodyAsString]); } } @end 

MyViewController.m:

 - (IBAction)myAction:(id)sender { DataAccess *data = [DataAccess getInstance]; [data sendRequests]; }