objective c - An AppDelegate's property is unexpectedly set to null -
first of all, appreciate helps.
well, use 3 nsstring objects in common in 2 views. , these view segued embedded navigationcontroller, mean start programming singleview.
in appdelegate.h, write
@property (weak, nonatomic) nsstring *crnturl; @property (weak, nonatomic) nsstring *crnttitle; @property (weak, nonatomic) nsstring *crnthtml;
for delegation.
and in first view, have webview , write
-(void)webviewdidfinishload:(uiwebview *)webview { appdelegate *appdelegate = [[uiapplication sharedapplication] delegate]; [uiapplication sharedapplication].networkactivityindicatorvisible = no; nsstring *url = [[nsstring alloc] initwithstring:[mywebview stringbyevaluatingjavascriptfromstring:@"document.url"]]; nsstring *title = [[nsstring alloc] initwithstring:[mywebview stringbyevaluatingjavascriptfromstring:@"document.title"]]; nsstring *html = [[nsstring alloc] initwithstring:[mywebview stringbyevaluatingjavascriptfromstring:@"document.all[0].outerhtml"]]; appdelegate.crnttitle = nil; appdelegate.crnttitle = [[nsstring alloc] initwithstring:title]; appdelegate.crnthtml = nil; appdelegate.crnthtml = [[nsstring alloc] initwithstring:html]; appdelegate.crnturl = nil; appdelegate.crnturl = [[nsstring alloc] initwithstring:url]; }
here, when put nslog, expected html source code dumped.
and in second view(a subclass of uiviewcontroller), write
- (void)viewdidload { // additional setup after loading view. appdelegate *appdelegate = [[uiapplication sharedapplication] delegate]; sourcehtml.text = appdelegate.crnthtml; nslog( @"%@", appdelegate.crnthtml ); nslog( @"%@", appdelegate.crnturl ); nslog( @"%@", appdelegate.crnttitle ); [super viewdidload]; }
and crnthtml unexpectedly set null while crnturl , crnttitle keep values.
do have ideas?
thank in advance.
masaru
you've declared properties in app delegate weak. using arc, object released , set nil if there's no strong reference it.
i imagine you're referencing title , url variable first view controller, html variable referenced in second view controller. once you're ready show html in second controller, has been released, since app delegate not holding on it.
try changing property declarations in app delegate strong:
@property (strong, nonatomic) nsstring *crnturl; @property (strong, nonatomic) nsstring *crnttitle; @property (strong, nonatomic) nsstring *crnthtml;
Comments
Post a Comment