objective c - table view use customized cell file and how ot use segue -
i user master-detail created project. on masterviewcontroller
, table cell use mastercell.h
, mastercell.m
build customized cell, code is:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; mastercell *cell = (mastercell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; cell = [[mastercell alloc] initwithframe:cgrectzero]; nsstring *value = [[mycontacts objectatindex:indexpath.row] valueforkey:@"name"]; cell.namecontentlabel.text = [nsstring stringwithformat:@"%@", value]; value = [[mycontacts objectatindex:indexpath.row] valueforkey:@"tele"]; cell.telecontentlabel.text=[nsstring stringwithformat:@"%@", value]; value = [[mycontacts objectatindex:indexpath.row] valueforkey:@"image"]; cell.myimageview.image = [[uiimage alloc] initwithcontentsoffile:value]; cell.accessorytype = uitableviewcellaccessorydisclosureindicator; return cell; }
and whan want click cell , push detailviewcontroller
, stroyboard use origin creat segue, didn't work, think segue not mastercell
, , had try change storyboard cell custom class, , was't not success.how do? thanks.
in storyboard should create segue not cell, entire uitableviewcontroller , set identifier, example "mysegue" , style "push".
then in tableviewcontroller should add
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [self performseguewithidentifier:@"mysegue" sender:self]; }
and
-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{ if([segue.identifier isequaltostring:@"mysegue"]){ //do stuff } }
Comments
Post a Comment