I가 다음과 같은 네 개의 파일,respondsToSelector는 항상 false
HttpClient.h
#import <Foundation/Foundation.h>
@interface HttpClient : NSObject{
....
}
....
@end
@protocol HttpClientDelegate <NSObject>
@required
- (void)handleReceivedData: (NSArray*)results returnArrayOrDic:(NSNumber *)returnArrayOrDic;
- (void)handleConnectionError: (NSURLConnection *)connection error:(NSError*)error;
@end
HttpClient.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"connectionDidFinishLoading");
NSLog(@"*********************************************");
....
NSLog(@"delegate in callee:%@", passedInDelegate);
if (passedInDelegate == nil) NSLog(@"passedInDelegate is NIL");
BOOL flag = [passedInDelegate respondsToSelector:@selector(handleReceivedData:)];
NSLog(flag ? @"Yes" : @"No");
flag = [passedInDelegate respondsToSelector:@selector(handleReceivedData)];
NSLog(flag ? @"Yes" : @"No");
if([passedInDelegate respondsToSelector:@selector(handleReceivedData:)]){
NSLog(@"handleReceivedData is founded");
[passedInDelegate performSelector:@selector(handleReceivedData:) withObject:jsonObject withObject:returnArrayOrDic];
}
NSLog(@"connectionDidFinishLoading");
}
ProductListViewController.h
@interface ProductListViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,HttpClientDelegate>
....
/*this is handle the call back*/
- (void)handleReceivedData: (NSArray*)results returnArrayOrDic:(NSNumber *)returnArrayOrDic;
- (void)handleConnectionError: (NSURLConnection *)connection error:(NSError*)error;
@end
ProductListViewControlle을 반환 r.m 인쇄 로그에서
/*callback of the httpClient*/
- (void)handleReceivedData: (NSArray*)results returnArrayOrDic:(NSNumber *)returnArrayOrDic{
NSLog(@"********************");
NSLog(@"handleReceivedData has been called");
....
}
,
- 2014-09-24 01:09:20.913 [298:60b] delegate in callee:<ProductListViewController: 0x1467d860>
- 2014-09-24 01:09:20.914 [298:60b] No
- 2014-09-24 01:09:20.915 [298:60b] No
passedInDelegate은 전무 예상대로 ProductListViewController에 할당되지 않습니다. 그러나 HttpClient에서 ProductListViewController로 콜백 할 때 [passedInDelegate respondsToSelector : @selector (handleReceivedData :)]와 [passedInDelegate respondsToSelector : @selector (handleReceivedData)]는 모두 NO입니다.
의견이 있으십니까?
감사 해머
'handleReceivedData :'메소드가 존재합니까? 'handleReceivedData : returnArrayOrDic :'메소드 만 구현 한 것 같습니다. – CrimsonChris
개체가 구현되지 않은 메시지에 응답해야하는 이유는 무엇입니까? –
이 경우 메서드에 NSArray와 NSNumber의 두 개의 paras가 있으므로 respondsToSelector : @selector (handleReceivedData :)]를 어떻게 변경해야합니까? – Hammer