iphone - Add Row to TableView from another UIView -
i have uiviewcontroller save button. when click add string array in uitableviewcontroller. have segue goes table view , want new object in array display row in table.
how can data view controller show on table view controller?
what doing isn't working.
uiviewcontroller:
- (void) prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{ if([[segue identifier] isequaltostring:@"showfindtable"]) { findtableviewcontroller *findtablevc = [segue destinationviewcontroller]; findtablevc.titles addobject:titlefield.text]; [findtablevc.tableview reloaddata]; } } uitableviewcontroller:
- (void)viewdidload { [super viewdidload]; self.titles = [[nsmutablearray alloc] init]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"findcell"; findtablecell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; cell.title.text = [self.titles objectatindex:[indexpath row]]; return cell; } inside table view controller initialize arrays. when add object revert empty array when viewdidload called? plan on persisting data using core data. think solve if problem. until then, how work?
i tried initialize title array 1 string. string displays. because re initializing array every time table view loaded. i/should initialize array somewhere else?
in project used this
crete object class want add data cell follows.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"whatsnewcell"; whatsnewcell *cell = (whatsnewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; //if (nil == cell) { cell = [[whatsnewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] ; cell.selectionstyle = uitableviewcellselectionstylenone; } return cell; } but here whatsnewcell subclass of uitableviewcell , in class create methods , add like
- (void)createcelllabels { albumnamelabel = [[uilabel alloc] initwithframe:cgrectmake(15.0, 5.0, 200.0, 50.0)]; albumnamelabel.textalignment = uitextalignmentleft; albumnamelabel.textcolor = [uicolor colorwithred:0.14 green:0.29 blue:0.42 alpha:1]; albumnamelabel.font = [uifont boldsystemfontofsize:15.0]; albumnamelabel.backgroundcolor = [uicolor clearcolor]; [self.contentview addsubview:albumnamelabel]; artistnamelabel = [[uilabel alloc] initwithframe:cgrectmake(15.0, 28.0, 200.0, 50.0)]; artistnamelabel.textalignment = uitextalignmentleft; artistnamelabel.textcolor = [uicolor graycolor]; artistnamelabel.font = [uifont boldsystemfontofsize:12.0]; artistnamelabel.backgroundcolor = [uicolor clearcolor]; [self.contentview addsubview:artistnamelabel]; genreslabel1 = [[uilabel alloc] initwithframe:cgrectmake(5.0, 0.0, 200.0, 25.0)]; genreslabel1.textalignment = uitextalignmentleft; genreslabel1.textcolor = [uicolor colorwithred:0.14 green:0.29 blue:0.42 alpha:1]; genreslabel1.font = [uifont boldsystemfontofsize:15.0]; genreslabel1.backgroundcolor = [uicolor clearcolor]; [self.contentview addsubview:genreslabel1]; } may helpful you.
Comments
Post a Comment