iphone - Xcode: Connection Between View Controllers and App Delegate -
this noob question can't head around it.
how make connection between 2 viewcontrollers or view controller , appdelegate? add following app delegate "h" file
@class rootviewcontroller; @interface tabbarwithsplitviewappdelegate : nsobject <uiapplicationdelegate, uitabbarcontrollerdelegate> { rootviewcontroller *rootviewcontroller; } @property (nonatomic, retain) iboutlet rootviewcontroller *rootviewcontroller; @end
and create connection in interface builder. root view controller app delegate , automatically tells me thats rootviewcontroller added above.
and if on app delegate "m" file:
#import "rootviewcontroller.h" nslog(@"controller %@",rootviewcontroller);
it gives bunch of numbers indicating there connection
but know xcode 4 changed since no longer have main.xib can create connection, connections programatically.
i`ve tried using same code without "iboutlet" adding:
rootviewcontroller = [[rootviewcontroller]alloc] init;
but nothing seems work.
can out?
thanks in advance
you want create ivar of view controller in app delegate.
viewcontroller *myvc; @property (nonatomic, retain) iboutlet viewcontroller *myvc;
then synthesize in implementation file.
then when view controller loads, call along lines of this:
- (void)viewdidload { appdelegateclass *appdelegate = (appdelegateclass *)[[uiapplication sharedapplication] delegate]; appdelegate.myvc = self; }
at point, have direct connection view controller app delegate. similarly, opposite call app delegate methods view controller. in case, you'd set delegate in view controller's header.
id delegate; @property (nonatomic, assign) id delegate;
again synthesizing in implementation file.
now when in viewdidload
, you'd call this:
- (void)viewdidload { self.delegate = (appdelegateclass *)[[uiapplication sharedapplication] delegate]; }
that should give need going, hope helps
Comments
Post a Comment