我正在这样的 RequestManeger
类中设置委托(delegate):
@protocol Resend_Verify_Delegate <NSObject>
@required
-(void)VerifyResponse:(NSString*)response;
-(void)Re_Failed;
@end
@interface RequestManeger : NSObject < ASIHTTPRequestDelegate > {
id <Resend_Verify_Delegate> Re_Delegate;
}
我也在 RequestManeger.m
文件中进行合成。
之后我将 RequestManeger.h
导入我的 ViewController.h
文件并确认我创建的协议(protocol)。在 ViewController.m
文件中,我正在调用一行来设置委托(delegate),如下所示:[RequestManeger sharedManeger].Re_Delegate = self;
并应用这些方法。
这是我如何设置来自 RequestManeger
类的调用:
NSString *url = [NSString stringWithFormat:@"http://someurl.com];
NSLog(@"%@",url);
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[request setRequestMethod:@"GET"];
[request setCompletionBlock:^{
NSDictionary *dictionary = [request.responseString JSONValue];
NSLog(@"%@",dictionary);
[self.Re_Delegate VerifyResponse:[dictionary valueForKey:@"Message"]];
}];
[request setFailedBlock:^{
NSLog(@"%@", request.error);
[self.Re_Delegate Re_Failed];
}];
[request startAsynchronous];
调用方法确实发生了,但它现在没有在 ViewController.m
文件中调用。
我有点沮丧, 任何帮助将不胜感激。
最佳答案
你做过这样的 sample 吗?? 在 Say TempViewController 类的 .h 中
@protocol TempViewControllerDelegate <NSObject>
- (void) yourMethod
@end
@interface TempViewController : UIViewController {
}
@property (assign) id<TempViewControllerDelegate> delegate;
@end
在您的 .m 文件中综合此委托(delegate)
在任何你想使用的地方调用你的代理方法 [self.delegate yourMethod]
现在,在另一个你想实现这个委托(delegate)的类中尝试这样......
#import "TempViewController.h"
@interface SecondViewerVC : UIViewController {
在你的 .m 文件中
初始化您的 TempViewController 对象
objTempVC = [[TempViewController alloc] initWithNibName:@"TempViewController" bundle:nil];
objTempVC.delegate = self;
并在这里实现你的方法
- (void) yourMethod { }
这绝对适合你:)
关于iphone - 委托(delegate)方法停止被调用(用于工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16957306/