ios - iPhone - How to implement delegate between my Static library and the app which the library is used? -


i have been creating cocoa static library in have public nsobject file created custom delegate. in app imported nsobject file , implemented delegate delegate not getting called... static library name glamapi.

the skuidpasser.h file of nsobject in library

#import <foundation/foundation.h>  @protocol subclassdelegate  <nsobject> @required - (void)methodnametocallback:(nsstring *)s; @end    @interface skuidpasser : nsobject  -(void)getskuidsfromcart:(nsstring *)skuids;  @property (nonatomic, weak) id  <subclassdelegate> delegatepasser;  @end 

and skuidpasser.m file

#import "skuidpasser.h"  @implementation skuidpasser  @synthesize delegatepasser;  -(void)getskuidsfromcart:(nsstring *)skuids{      nslog(@"getskuidsfromcart %@",skuids);      [delegatepasser methodnametocallback:skuids];  } @end 

and method called viewcontroller in static library

- (ibaction)cartshowevent:(id)sender {     if (![cartbadge ishidden]) {         buyclicked = true;          [self loadcart];         [self showcartitemsall];          self.cartview.frame = self.view.bounds;         [self.view addsubview:self.cartview];          skuidpasser *pass = [[skuidpasser alloc] init];         [pass getskuidsfromcart:@"sssss"];     } else {             [utilities alert:@"no products display !!!"];    } } 

the viewcontroller custom delegate has implemented viewcontroller.h

#import <glamapi/skuidpasser.h>  @interface viewcontroller : uiviewcontroller<subclassdelegate>{     skuidpasser *sk; } 

viewcontroller.m

- (void)viewdidload {     [super viewdidload];      sk = [[skuidpasser alloc] init];     sk.delegatepasser = self;      nslog(@"sk.delegatepasser %@",sk.delegatepasser); }  - (void)methodnametocallback:(nsstring *)s {     nslog(@"methodnametocallback %@",s); } 

i didn't error method not calling..please me resolve this

the first thing need understand each instance object of class entirely different entity , maintains it's state separately. in case have created object of static library in viewdidload: , set delegate accordingly, when making call method getskuidsfromcart, using different instance never set delegate property. that's why there no callback.

to solve this, can set delegate in method cartshowevent: before making call,

skuidpasser *pass = [[skuidpasser alloc] init]; pass.delegatepasser = self; [pass getskuidsfromcart:@"sssss"]; 

however suggest should use instance variable of library created in viewdidload:

- (ibaction)cartshowevent:(id)sender { if (![cartbadge ishidden]) {     buyclicked = true;      [self loadcart];     [self showcartitemsall];      self.cartview.frame = self.view.bounds;     [self.view addsubview:self.cartview];      //no need create object.     //skuidpasser *pass = [[skuidpasser alloc] init];      //use created instance object     [sk getskuidsfromcart:@"sssss"];     }        else {             [utilities alert:@"no products display !!!"];         }     } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -