iphone - Getting property of an array with viewControllers -
i got array viewcontrollers different types, named viewcontrollersarray
first check if type correct (questionviewcontroller) , want print out property.
for(nsuinteger = 0; i<viewcontrollersarray.count; i++) { if ([[viewcontrollersarray objectatindex:i] iskindofclass:[questionviewcontroller class]]) { nslog(@"%@",((questionviewcontroller*)[viewcontrollersarray objectatindex:i]).getqanswer ); } }
however shows me (null) instead of nsstring property.
edit
what got far this:
for(nsuinteger = 0; i<viewcontrollersarray.count; i++) { if ([[viewcontrollersarray objectatindex:i] iskindofclass:[questionviewcontroller class]]){ nslog(@"ident: %@", [[viewcontrollersarray objectatindex:i] ident]); nslog(@"answer: %@", [[viewcontrollersarray objectatindex:i] getqanswer]); } }
the second nslog (getqanswer) works. getqanswer method in questionviewcontroller. first nslog (ident) shows incorrect output (null), property:
@property (strong, nonatomic) nsstring *ident;
you typecasted questionviewcontroller
use
nslog(@"%@", [[viewcontrollersarray objectatindex:i] getqanswer]);
edit:
as per comment viewcontrollersarray[0]
gives sendviewcontroller
.
you should change
iskindofclass:
to
if( [[viewcontrollersarray objectatindex:i] class] == [questionviewcontroller class])
Comments
Post a Comment