objective c - ios error terminating -[__NSArrayM setRoleHistorys:]: -
im trying make user role page data login. created own delegate function call webservice app getting crash due to-[__nsarraym setrolehistorys:]: unrecognized selector sent instance. here code: in .m file :
- (void)parserdidstartdocument:(nsxmlparser *)parser { nodecontent = [[nsmutablestring alloc]init]; } - (void)parserdidenddocument:(nsxmlparser *)parser { arrayitems = [[nsmutablearray alloc] init]; u serroledataparser *userroleparser = [[userroledataparser alloc] init]; // userrole *currentstudent = (userrole *) arrayitems; nsstring *username = username.text; nslog(@"the string value%@",username); [userroleparser getuserhistoryforindex:0 loginid:username.text]; nslog(@"the string user value %@",username.text); userroleparser.delegate = self; } - (void) didrecievedata : (nsarray *) userhistories forindex :(int) index { arrayitems = [[nsmutablearray alloc] init]; userrole *roles = (userrole *) arrayitems; roles.rolehistorys = userhistories; datadisplay.text = roles.role; nslog(@"the success data%@", datadisplay.text); }
in delegate file .h
@interface userrole : nsobject @property (nonatomic,copy) nsstring *username; @property (nonatomic,copy) nsstring *role; @property (nonatomic,copy) nsstring *empcode; @property (nonatomic,copy)nsmutablearray * rolehistorys; @end
dataparser.h file (delegate)
#import <foundation/foundation.h> #import "userrole.h" @protocol userroledataparserdelegate <nsobject> - (void) didrecievedata : (nsarray *) userhistories forindex :(int) index ; @end @interface userroledataparser : nsobject<nsxmlparserdelegate> { nsmutabledata *xmldata; nsxmlparser *userroleparser; nsmutablestring *capturedstring; bool capturecharacters; nsmutablearray *userhistories; } - (void) getuserhistoryforindex : (int) index loginid :(nsstring*) loginid; @property (weak,nonatomic) id <userroledataparserdelegate> delegate; @property (nonatomic) int index; @end
am getting output in nslog app getting crash.
this code isn't correct:
arrayitems = [[nsmutablearray alloc] init]; userrole *roles = (userrole *) arrayitems;
you can't cast array custom class type (unless have subclassed nsmutablearray
, instance of subclass type). need create instance of or find correct instance want before try use it.
Comments
Post a Comment