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



我正在像这样在RequestManeger类中设置一个委托:

@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文件,并确认我创建的协议。在ViewController.m文件中,我调用一行来设置委托,像这样:[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文件中调用。

我有点沮丧,

您做过这个样例吗??在你的。h中说TempViewController类

@protocol TempViewControllerDelegate <NSObject>
- (void) yourMethod
@end
@interface TempViewController : UIViewController {
}
@property (assign) id<TempViewControllerDelegate> delegate;
@end

在你的。m文件中合成这个委托

在任何你想使用的地方调用委托的方法[self.delegate yourMethod]

现在,在另一个你想要实现这个委托的类中尝试这样做。

#进口"TempViewController.h"

@interface SecondViewerVC: UIViewController{}

在你的。m文件

初始化你的TempViewController对象

objTempVC = [[TempViewController alloc] initWithNibName:@"TempViewController" bundle:nil];    
objTempVC.delegate = self;

在这里实现你的方法

  • (void) yourMethod {}

这对你肯定有用:)

检查Re_Delegate是否为nil…

为什么要写self.Re_Delegate?我想一定有[Re_Delegate Re_Failed]你没有对象的属性

相关内容

最新更新