objective c - Unable to add string into an mutable array -
i trying upload assignments table in different view controller. first when click on upload button code runs.
- (ibaction)uploadassignment:(id)sender { nameofassignmentasstring = self.nameofassignment.text; nslog(@"%@", nameofassignmentasstring); nsinteger row; row = [self.subjectpicker selectedrowincomponent:0]; subjectofassignmentasstring = [subjectarray objectatindex:row]; nslog(@"%@", subjectofassignmentasstring); nsdate *deadline = [self.deadlinepicker date]; nsdateformatter *dateformat = [[nsdateformatter alloc] init]; [dateformat setdateformat:@"dd/mm/yyyy"]; deadlineofassignmentasstring = [dateformat stringfromdate:deadline]; nslog(@"%@",deadlineofassignmentasstring); homeworkviewcontroller *hvc; [hvc.nameofassignmentinanarray addobject:nameofassignmentasstring]; [hvc.subjectofassignmentinanarray addobject:subjectofassignmentasstring]; [hvc.deadlineofassignmentinanarray addobject:deadlineofassignmentasstring]; nslog(@"%@",hvc.nameofassignmentinanarray.count); }
then in homeworkviewcontroller.h code
@interface homeworkviewcontroller : uiviewcontroller <uigesturerecognizerdelegate,uitableviewdatasource,uitableviewdelegate> { int i; } @property (strong, nonatomic) iboutlet uiview *mainmenu; @property (strong, nonatomic) iboutlet uibutton *homeworkbutton; @property (strong, nonatomic) iboutlet uibutton *uploadbutton; @property (strong, nonatomic) nsmutablearray *nameofassignmentinanarray; @property (strong, nonatomic) nsmutablearray *subjectofassignmentinanarray; @property (strong, nonatomic) nsmutablearray *deadlineofassignmentinanarray;
i did initialise in homeworkviewcontroller.m file. reason string not being added array.
you declare hvc never assign value it. therefore cannot hold in itself. reason designers of objective-c decided it's not error send messages nil objects, might not noticed.
Comments
Post a Comment