ios - text not showing in table view cell unless cell touched -
i have table view set in traditional master/detail way in iphone app. when click save on detail screen (after adding information want), switches master list, however, text that's supposed appear in cell in master list doesn't appear until touch cell finger, however, if touch cell finger segues detail screen , have click "back" master list cell has text it's supposed to. interestingly, table view image appearing upon save - don't have touch cell make image appear in same way have make text appear.
clicking "save" button in detail screen runs code. mnemonicfield.text
gets saved currenttopic , later set text appears in cell
- (ibaction)save:(id)sender { [self.currenttopic settopic:topicfield.text]; [self.currenttopic setmnemonic:mnemonicfield.text]; //this should appear in cell on master [self.currenttopic setmood: self.mood]; [self.delegate addtopicviewcontrollerdidsave]; }
the master table view controller delegate referred in above method. here method.
-(void)addtopicviewcontrollerdidsave{ nserror *error = nil; nslog(@"saving topick"); nsmanagedobjectcontext *context = self.managedobjectcontext; if (![context save:&error]){ nslog(@"error: %@", error); } [self.navigationcontroller poptorootviewcontrolleranimated:yes]; }
in cellforrowatindexpath
, call method setup cell
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"topiccell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier: cellidentifier forindexpath:indexpath]; [self configurecell:cell atindexpath:indexpath];//sets cell, see below return cell; }
here's configurecell:atindexpath
sets cell. again, note both image , textlabel.text set in method have touch cell finger make text appear
- (void)configurecell:(uitableviewcell *)cell atindexpath:(nsindexpath *)indexpath { // configure cell... topic *topic = [self.fetchedresultscontroller objectatindexpath:indexpath]; cell.textlabel.text = topic.mnemonic; nslog(@"jokemood in configure cell %@", joke.mood); uiimage *funnyimage = [uiimage imagenamed: @"nslaugh.png"]; uiimage *badimage = [uiimage imagenamed: @"nsbad.png"]; uiimage *crapimage = [uiimage imagenamed: @"nscrap.png"]; uiimage *mehimage = [uiimage imagenamed: @"nsmeh.png"]; uiimage *smileimage = [uiimage imagenamed: @"nssmile.png"]; switch ([topic.mood intvalue]) { case 0: // nslog(@" topic table 0"); cell.imageview.image = crapimage ; break; case 1:
after experimentation, determined problem line cell.textlabel.text = topic.mnemonic;
in above function. if take line out, title shows in cell in master list upon saving in detail screen. however, if take line out, when start application, title not getting assigned when data's pulled core data. so, either way there's problem. if line cell.textlabel.text = topic.mnemonic;
left in above function, have touch cell in master list (after saving in detail) text appear, if take line out textlabel.text not getting assigned when application pulls core data. neither option acceptable.
do know why might happening?
for sake of completion here's prepareforsegue in master view controller setup currenttopic on destination view controller based on topic in master view controller
if ([[segue identifier] isequaltostring:@"addjoke"]){ mmaddtopicviewcontroller *ajvc = (mmaddtopicviewcontroller *)[segue destinationviewcontroller]; ajvc.delegate = self; ajvc.mood = nil; topic *newtopic = (topic *)[nsentitydescription insertnewobjectforentityforname:@"topic" inmanagedobjectcontext: [self managedobjectcontext]]; nsmutableset* relationship = [self.rootobject mutablesetvalueforkey:@"subitems"]; nsmanagedobject *lastobject = [self.fetchedresultscontroller.fetchedobjects lastobject]; double lastobjectdisplayorder = [[lastobject valueforkey:@"displayorder"] doublevalue]; [newtopic setvalue:[nsnumber numberwithdouble:lastobjectdisplayorder + 1.0] forkey:@"displayorder"]; [relationship addobject:newjoke]; ajvc.currenttopic = newtopic; ///currenttopic in destination view controller set topic master view controller
i added [self.tableview reloaddata];
in save method in master view controller, called detail controller (master serves detail's delegate). lynda.com tutorial copied didn't have use self.tableview reloaddata
, not sure why code did.
-(void)addtopicviewcontrollerdidsave{ nserror *error = nil; nslog(@"saving cock"); nsmanagedobjectcontext *context = self.managedobjectcontext; if (![context save:&error]){ nslog(@"error: %@", error); } [self.navigationcontroller poptorootviewcontrolleranimated:yes]; [self.tableview reloaddata]; }
Comments
Post a Comment