iphone - 委托(delegate)方法停止被调用(用于工作)

标签 iphone ios objective-c delegates protocols

我正在这样的 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/

相关文章:

objective-c - 在编写 CodeRunner 文档时如何包含非框架库?

iphone - iPhone中的dvr监控系统开发

iphone - 如何读取 Plist 数据到 UITableView

ios - 原生 iOS 国家/地区选择器

c - 从 UITextField 获取文本然后将其放入外部类的最佳方法是什么?

objective-c - 如何正确使用 swipeWithEvent 导航 webView,Obj-C

iphone - 数据格式化程序暂时不可用,将在 'continue' 后重试

ios - 从泛型方法接收参数

ios - 如何在 Xcode 中调试 Delphi iOS FireMonkey 应用程序?

objective-c - 绑定(bind) NSSlider 来控制 IKImageBrowserView 的缩放