object - iOS, Unable to delegate outside of viewDidLoad -
i have appdelegate.h
#import <uikit/uikit.h> @interface appdelegate : nsobject <uiapplicationdelegate> { uiwindow *window; nsstring *name; } @property (nonatomic, retain) nsstring *name; @end
and .m file
@synthesize name; - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { name=@"john"; return yes; }
now...i want name controller, if try call inside viewdidload methods, works..
- (void)viewdidload { appdelegate *test= (appdelegate *)[[uiapplication sharedapplication] delegate]; nslog(@"%@", test.name); }
but if try same thing in initwithnibname didn't work...
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { appdelegate *test= (appdelegate *)[[uiapplication sharedapplication] delegate]; nslog(@"%@", test.name); }
anyone can me out? problem driving me crazy...
if overriding -initwithnibname:
, need return instance of class (or self
); try following code in -initwithnibname:
. working me.
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { appdelegate *test= (appdelegate *)[[uiapplication sharedapplication] delegate]; nslog(@"%@", test.name); if (self = [super initwithnibname:nibnameornil bundle:nibbundleornil]) { } return self; }
i think may useful you.
Comments
Post a Comment