Reputation: 4079
i am setting up a delegate in a RequestManeger
class like this :
@protocol Resend_Verify_Delegate <NSObject>
@required
-(void)VerifyResponse:(NSString*)response;
-(void)Re_Failed;
@end
@interface RequestManeger : NSObject < ASIHTTPRequestDelegate > {
id <Resend_Verify_Delegate> Re_Delegate;
}
i am synthesizing in the RequestManeger.m
file as well.
after that i am importing the RequestManeger.h
int my ViewController.h
file and confirm to the protocol i have created. int the ViewController.m
file i am calling a line to set the delegate like so : [RequestManeger sharedManeger].Re_Delegate = self;
and applying the methods as well.
here is how i set the call from the RequestManeger
class :
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];
calling to the methods does happend, but it does not invoked in the ViewController.m
file now.
i am kind'a frustrated about it, any help would be kindly appreciated.
Upvotes: 0
Views: 186
Reputation: 1318
Have you done like this sample ?? In your .h of Say TempViewController class
@protocol TempViewControllerDelegate <NSObject>
- (void) yourMethod
@end
@interface TempViewController : UIViewController {
}
@property (assign) id<TempViewControllerDelegate> delegate;
@end
Synthesize this delegate in your .m file
call your delegate's method wherever you want using [self.delegate yourMethod]
Now , In another class where you want to implement this delegate try like this..
#import "TempViewController.h"
@interface SecondViewerVC : UIViewController { }
Init your object of TempViewController
objTempVC = [[TempViewController alloc] initWithNibName:@"TempViewController" bundle:nil];
objTempVC.delegate = self;
And implement your method here
This will work for you definitely :)
Upvotes: 2
Reputation: 1703
check if Re_Delegate is nil...
why did you write self.Re_Delegate? i think there must be [Re_Delegate Re_Failed] you have not property of the object
Upvotes: 1