RestKit iOS:简单请求错误
我是 iOS 开发新手,目前正在使用 ARC 测试适用于 iOS 的 RestKit 0.9.3 和 xCode 4.2,我遇到了一些简单的 get 请求问题。
我遵循本教程: https://github.com/RestKit /RestKit/wiki/Tutorial-%3A-Introduction-to-RestKit
我尝试在 TouchUpInside
a 上向我的 Web 服务发送一个简单的获取请求UIButton
。
但我收到一条“ 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
我在互联网上搜索,但没有找到解决方案
有人可以 帮我 ?
谢谢,
I'm newbie on iOS development and I'm currently testing RestKit 0.9.3 for iOS with xCode 4.2 using ARC and I encounter some problem for a simple get request.
I following this tutorial : https://github.com/RestKit/RestKit/wiki/Tutorial-%3A-Introduction-to-RestKit
I try to send a simple get request to my webservices on TouchUpInside
a UIButton
.
But I receive an " EXC_BAD_ACCESS " : [6373:fb03] *** -[DataAccess respondsToSelector:]: message sent to deallocated instance 0x8275160
The application stop at this line, on RKRequest.m
file :
if ([self.delegate respondsToSelector:@selector(requestDidStartLoad:)]) {
[self.delegate requestDidStartLoad:self];
}
My code :
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
I searched on the Internet but I didn't found the solution
Someone could help me ?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是一种解决方案。我更改了您的代码以使用单例。我认为问题是当调用回调函数时,因为他无法再访问该实例。
DataAccess.m:
MyViewController.m:
This may be one solution. I changed your code to use a singleton. I think the problem is when the callback function is called because he can no longer access the instance.
DataAccess.m:
MyViewController.m: