ios - Can't access parent view controller's variables -


i trying apply basic inheritance concept, need display parent viewcontorller's textfield.text's in child view controller. getting null values

parent.h

@interface editeventviewcontroller : uitableviewcontroller {  uitextfield *texteventname;     uitextfield *texteventlocation;     uitextfield *textstarttime;     uitextfield *textendtime;     uitextfield *textdate;     uitextfield *textenddate;      //tried iboutlet version  such     //iboutlet uitextfield *texteventname;//this didnt work }  @property (nonatomic, strong) iboutlet uitextfield *texteventname; @property (nonatomic, strong) iboutlet uitextfield *texteventlocation; @property (nonatomic, strong) iboutlet uitextfield *textstarttime; @property (nonatomic, strong) iboutlet uitextfield *textendtime; @property (nonatomic, strong) iboutlet uitextfield *textdate; @property (nonatomic, strong) iboutlet uitextfield *textenddate; 

parent.m

  @synthesize textenddate=_textenddate; @synthesize textdate=_textdate; @synthesize textendtime=_textendtime; @synthesize texteventname=_texteventname; @synthesize textstarttime=_textstarttime; @synthesize texteventlocation=_texteventlocation;  //test inherritance here      deletefromcalendar *deletecontrol=[[deletefromcalendar alloc] init];     nslog(@"delete request text name %@",self.texteventname.text);     [deletecontrol displayparentstrings]; 

child.h

#import "editeventviewcontroller.h"  @interface deletefromcalendar : editeventviewcontroller  -(void)displayparentstrings;  @end 

child.m

-(void)displayparentstrings {     nslog(@"display parent strings");     nslog(@"deletefromcalendar event name %@",texteventname.text);     nslog(@"deletefromcalendar  event  %@",texteventlocation.text); } 

nslog:

delete request text name aeronautical knowledge review deletefromcalendar event name (null) deletefromcalendar  event lcoation (null) 

why null?

the problem here you're using self.texteventname.text access texteventname property in parent.m, you're using texteventname.text in child.m. that's meaningless -- it's equivalent of this:

[[  texteventname] text];   // error: you're not specifying receiver of message 

if want access property of object, need specify which object. in case, object self.

change code in -displayparentstrings thus:

nslog(@"deletefromcalendar event name %@", self.texteventname.text); nslog(@"deletefromcalendar  event  %@", self.texteventlocation.text); 

adding self. solve problem.


Comments