Ios xcode-发送到实例的无法识别的选择器
我在另一个类中调用了方法(它们都是单例) webserviceheloper.hIos xcode-发送到实例的无法识别的选择器,ios,objective-c,Ios,Objective C,我在另一个类中调用了方法(它们都是单例) webserviceheloper.h @interface WebserviceHelper : NSObject { int currentType; NSString *SERVER_URL; WebserviceManager *webService; } @property (nonatomic, assign) id delegate; - (void)retrieveStudentwithCode:(NSStri
@interface WebserviceHelper : NSObject {
int currentType;
NSString *SERVER_URL;
WebserviceManager *webService;
}
@property (nonatomic, assign) id delegate;
- (void)retrieveStudentwithCode:(NSString *)code {
currentType = STUDENT_TYPE;
NSString *param = [NSString stringWithFormat:@"token=uencom&cid=%@", code];
NSString *link = [NSString stringWithFormat:@"%@getStudentInfo", SERVER_URL];
[webService retrieveData:link withParameters:param];
}
调用webservice并获取它缓存在接收数据中的数据后。我检查了一下,一切正常
但是当它交付给didfishload
时,这里会发生错误
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)receivedData {
data = [NSMutableData new];
[data appendData:receivedData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
//it carsh here
[delegate: data];
}
调用堆栈:
2014-08-20 10:39:05.187 School-Link[1030:60b] -[WebserviceHelper :]: unrecognized selector sent to instance 0xa88a420
2014-08-20 10:39:05.188 School-Link[1030:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WebserviceHelper :]: unrecognized selector sent to instance 0xa88a420'
*** First throw call stack:
(
0 CoreFoundation 0x01bf31e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018f08e5 objc_exception_throw + 44
2 CoreFoundation 0x01c90243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01be350b ___forwarding___ + 1019
4 CoreFoundation 0x01be30ee _CF_forwarding_prep_0 + 14
5 School-Link 0x00030c82 -[WebserviceManager connectionDidFinishLoading:] + 242
6 Foundation 0x016b9e49 ___NSURLConnectionDidFinishLoading_block_invoke + 40
7 Foundation 0x016507e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
8 Foundation 0x014d8f5e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
9 Foundation 0x014d8ec6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
10 Foundation 0x014d8dd8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
11 Foundation 0x014d9188 _NSURLConnectionDidFinishLoading + 43
12 CFNetwork 0x02a3169f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 111
13 CFNetwork 0x02a2f3de ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
14 CoreFoundation 0x01b94c69 CFArrayApplyFunction + 57
15 CFNetwork 0x02998441 _ZN19RunloopBlockContext7performEv + 155
16 CFNetwork 0x02a7a3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
17 CFNetwork 0x02998257 _ZN17MultiplexerSource7performEv + 299
18 CFNetwork 0x0299806c _ZN17MultiplexerSource8_performEPv + 76
19 CoreFoundation 0x01b7c77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
20 CoreFoundation 0x01b7c1d5 __CFRunLoopDoSources0 + 437
21 CoreFoundation 0x01b991ae __CFRunLoopRun + 910
22 CoreFoundation 0x01b989d3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x01b987eb CFRunLoopRunInMode + 123
24 GraphicsServices 0x0338d5ee GSEventRunModal + 192
25 GraphicsServices 0x0338d42b GSEventRun + 104
26 UIKit 0x005b0f9b UIApplicationMain + 1225
27 School-Link 0x00018f6d main + 141
28 libdyld.dylib 0x03026701 start + 1
29 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
您不显示委托的声明,但是以下语句:
[delegate: data];
应该是:
[delegate haveSomeData:data];
(或类似内容)您是否在WebserviceHelper.h文件中创建了如下协议
@protocol WebserviceHelperDelegate <NSObject>
@required
-(void)reciveData:(NSData *)data;//or your method
@end
并从调用webservice类并分配委托的位置实现此方法
-(void)reciveData:(NSData *)data{
}
试试这个,在WebserviceHelper.h中有一个协议声明
@protocol studentDataDelegate <NSObject>
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
@end
那么,哪个类确认上述协议应该实现委托方法,比如
@interface RequestingDataClass : UIViewController <studentDataDelegate>
将对象传递给代理的方式是错误的!遵循@trojanfoe语法我对objective c不熟悉,所以我没有这方面的经验。我应该在另一个类中创建新方法来处理来自该类的数据吗one@MohammadShaker如果你想通知代表已经收到数据,我想你会这么做的,你将需要一个类似于我的答案所示的方法。我尝试了这个代码,它让我有很多问题,我在我的朋友代码工作,我不知道他是如何建立它的,但谢谢你的朋友
@protocol studentDataDelegate <NSObject>
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
@end
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
[self.delegate WebserviceHelper:self didStudentDataDownloadCompleteWithData:data];
}
@interface RequestingDataClass : UIViewController <studentDataDelegate>
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
{
webserviceHelper.delegate=self;
// Do something with the `data`
}