ios - selected row in custom cell doesn't pass complete data from segue to another view controller -
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{ self.data= [self.namelist objectatindex:indexpath.row]; self.data= [self.rolllist objectatindex:indexpath.row]; [self performseguewithidentifier:@"detailvc" sender:self]; }
i've displayed student's name , roll number in custom cell. when select 1 row pass data uiviewcontroller
, display in labels. i've 1 nsobject
type file called 'name' , i've 1 variable called 'data' of type 'name'. here's code in didselectrowatindexpath
namelist
overlapped rolllist
stored on same variable self.data
. if rolllist
line removed works good. when store rolllist
in self.data
overlap other.
where, self.namelist
variable of type nsmutablearray
contains name of student , similarly, self.rolllist
contains student's roll.
below code pass data segue. here detailvc
destinationviewcontroller
, vc.data
variable of type 'name' , self.data
variable of same type.
-(void) prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{ if([segue.identifier isequaltostring:@"detailvc"]){ detailvc *vc = (detailvc *) segue.destinationviewcontroller; vc.data = self.data; } }
overlapping fundamental thing.
in case in nsobject type file (name) have add 2 variable
nsnumber *rollno; nsstring *name;
after
-- update --
@interface tablevc : uiviewcontroller { name *data; } -(void)viewdidload { data = [[name alloc] init] } -(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{ self.data.name = [self.namelist objectatindex:indexpath.row]; self.data.rollno = [self.rolllist objectatindex:indexpath.row]; [self performseguewithidentifier:@"detailvc" sender:self]; }
then
-(void) prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{ if([segue.identifier isequaltostring:@"detailvc"]){ detailvc *vc = (detailvc *) segue.destinationviewcontroller; vc.data = self.data; } }
------ detail vc ---
@property (nonatomic, strong) name *data; -(void)viewdidload { self.labelrollno.text = self.data.rollno; self.labelname.text = self.data.name; }
Comments
Post a Comment