Я только начинаю с Objective C и Restkit
Я создал пример приложения и добавил RKRequestDelegate в файл MyAppDelegate
@interface MyAppDelegate : NSObject <UIApplicationDelegate, RKRequestDelegate> {…
и добавил
RKClient* client = [RKClient clientWithBaseURL:@"http://localhost:3000"];
NSLog(@"I am your RKClient singleton : %@", [RKClient sharedClient]);
[client get:@"/titles.json" delegate:self];
в MyAppDelegate.m в
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method
Я также добавил метод к MyAppDelegate.m
- (void) request: (RKRequest *) request didLoadResponse: (RKResponse *) response {
if ([request isGET]) {
NSLog (@"Retrieved : %@", [response bodyAsString]);
}
}
, пока все хорошо, все работает, и я вижу результаты из моих Railsприложение в выводе !!!
Поскольку эти вещи не принадлежат MyAppDelegate.m, я перемещаю эти вещи в свои модели.В свой Titles.h я добавил
@interface Titles : NSManagedObject <RKRequestDelegate> {
, а в Titles.m я добавил
+ (void) update {
[[RKClient sharedClient] get:@"/titles.json" delegate:self];
}
и
- (void) request: (RKRequest *) request didLoadResponse: (RKResponse *) response {
if ([request isGET]) {
NSLog (@"Retrieved : %@", [response bodyAsString]);
}
}
В своем MyAppDelegate.m я заменил:
RKClient* client = [RKClient clientWithBaseURL:@"http://localhost:3000"];
NSLog(@"I am your RKClient singleton : %@", [RKClient sharedClient]);
[client get:@"/titles.json" delegate:self];
с
RKClient* client = [RKClient clientWithBaseURL:@"http://localhost:3000"];
NSLog(@"I am your RKClient singleton : %@", [RKClient sharedClient]);
[Titles update];
, когда я бегу сейчас, я не получаю никакого вывода.Я поставил несколько точек останова, одну в - (void)didFinishLoad:(RKResponse*)response
в файле RKRequest, и там тест if для:
if ([_delegate respondsToSelector:@selector(request:didLoadResponse:)]) {
[_delegate request:self didLoadResponse:finalResponse];
}
не проходит, пока он успешен в моей первой попытке (когда все в MyAppDelegate)
Я проверил переменную _delate в de debugger, и она говорит: _delegate = MyAppDelegate в моей первой попытке и _delegate = Заголовки в моей второй попытке (обе должны быть выполнены)
Почему происходит сбой данного отклика ToSelector?(делегат правильный, а метод существует в заголовках)