iphone - How to implement custom delegate methods for my view controllers -


in app there 2 tabbars. in tab-0 parent class "firstviewcontroller" , in tab-1 parent class "secondviewcontroller". in "secondviewcontroller" have declared protocol , custom delegate method. want pass information in "firstviewcontroller"(fvc). fvc has assigned delegate.

now doubt is, right in "svc". how can assign "fvc" delegate of "svc"?

in "svc"

[[self delegate] sendcoordinates:self]; 

definition of method in "fvc". execute method, first need assign "fvc" delegate.

i hope clear in explaining problem.

thanks in advance.

you need set delegate. let me demonstrate:

`svc.h`  @interface svc {     id _delegate; }  - (void)setdelegate:(id)delegate; //sets delegate - (id)delegate; //gets delegate  @end  @protocol svcdelegate  - (void)sendcoordinates:(svc *)svc;  @end 

then, in svc.m, call delegate in same way showed in question, [[self delegate] sendcoordinates:self];

now, in fvc, you'll need #import svc.h , initialise object.

svc*svcobject = [[svc alloc] init]; [svcobject setdelegate:self]; //self refers fvc - think you're missing 1 //work object , when you're done, rid of in dealloc: [svcobject setdelegate:nil]; [svcobject release]; 

in same class, implement - (void)sendcoordinates:(svc *)svc , called after set delegate.

i think you're missing setdelegate: stage, why doesn't work.

hope helps!

note: in svc, remember retain delegate, or become nil , no delegate methods never called. don't forget release delegate once you're done.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -