objective c - iOS: How to pass first view controller label data of table view cell to textView of second view controller? -
i working on app in want show table view cell label data of first view controller textview of second view controller when click on button. have implemented code when click on button textview of second view becomes blank. kindly suggest me doing mistake in following code have tried many times couldn't succeeded.


first view controller:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view. self.jobpostedtableview.datasource = self; //slide navigation [self.sidenavigation addtarget:[slidenavigationcontroller sharedinstance] action:@selector(toggleleftmenu) forcontrolevents:uicontroleventtouchupinside]; webmanager *manager = [webmanager sharedinstance]; [manager getjobpostedwithcompletionblock:^(id response){ nsdictionary *dictionary = (nsdictionary *)response; // read data json nsdictionary *responseobject = [dictionary objectforkey:@"response"]; nslog(@"the array%@",responseobject); self.bids = [responseobject objectforkey:@"bids"]; self.job_description = [responseobject objectforkey:@"job_description"]; self.job_id = [responseobject objectforkey:@"job_id"]; self.job_completed = [responseobject objectforkey:@"job_completed"]; self.job_latitude = [responseobject objectforkey:@"job_latitude"]; self.job_longitude = [responseobject objectforkey:@"job_longitude"]; self.job_priority = [responseobject objectforkey:@"job_priority"]; self.job_start_date = [responseobject objectforkey:@"job_start_date"]; self.job_title = [responseobject objectforkey:@"job_title"]; [self.jobpostedtableview reloaddata]; }]; self.reversedgeocodes = [nsmutabledictionary dictionary]; } #pragma mark - tableview data source - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [self.job_title count]; } - (nsinteger) numberofsectionsintableview:(uitableview *)tableview { return 1; } - (uitableviewcell *) tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"jobtableviewcell"; jobtableviewcell *cell = (jobtableviewcell *)[self.jobpostedtableview dequeuereusablecellwithidentifier:cellidentifier]; if(cell == nil) { cell = [[jobtableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } // comparing array string display urgent image if ([[self.job_priority objectatindex:indexpath.row] isequaltostring:@"urgent"]) { cell.urgentlabel.hidden = no; } else { cell.urgentlabel.hidden = yes; } // condition whether job completed open or closed if ([[self.job_completed objectatindex:indexpath.row] isequaltostring:@"1"]) { cell.jobstatus.text = @"open"; [cell.jobstatus settextcolor:[uicolor colorwithred:(84/255.f) green:(56/255.f) blue:(255/255.f) alpha:1.0f]]; cell.flagimage.image = [uiimage imagenamed:@"jobposted_opened.png"]; } else { cell.jobstatus.text = @"closed"; [cell.jobstatus settextcolor:[uicolor colorwithred:(179/255.f) green:(179/255.f) blue:(180/255.f) alpha:1.0f]]; cell.flagimage.image = [uiimage imagenamed:@"jobposted_closed.png"]; } cell.jobtitle.text = [self.job_title objectatindex:indexpath.row]; cell.jobcontent.text = [self.job_description objectatindex:indexpath.row]; cell.bidslabel.text = [[self.bids objectatindex:indexpath.row ]stringvalue]; // latitude , longitude float lat = [self.job_latitude[indexpath.row] floatvalue]; float lng = [self.job_longitude[indexpath.row] floatvalue]; [self locationnamewithlat:lat lng:lng completionhandler:^(nsstring *locationname, nserror *error) { cell.locationjob.text = locationname; }]; return cell; } - (ibaction)onclickjobbutton:(id)sender { jobdetailsviewcontroller *vc = [self.storyboard instantiateviewcontrollerwithidentifier:@"jobdetailsviewcontroller"]; [self.navigationcontroller pushviewcontroller:vc animated:yes]; nsindexpath *indexpath = [self.jobpostedtableview indexpathforselectedrow]; jobdetailsviewcontroller *jobdetailscontroller = [[jobdetailsviewcontroller alloc]init]; jobdetailscontroller.jobdetailview = [self.job_description objectatindex:indexpath.row]; } second view controller:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view. webmanager *manager = [webmanager sharedinstance]; nsstring *user_name = manager.completename; self.namelabel.text = user_name; self.jobtextview.text = self.jobdetailview; }
if using segues, can send text using prepareforsegue method:
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { // make sure segue name in storyboard same line if ([[segue identifier] isequaltostring:@"your_segue_name_here"]) { // reference destination view controller yoursecondviewcontroller *vc = [segue destinationviewcontroller]; // pass labeldata string [vc settextstring:labeldata]; } } and don't forget declare string property in secondviewcontroller.h
@property(nonatomic,strong) nsstring *textstring;
Comments
Post a Comment