ios - UITableView - reloadData from separate class -
i searched , looked on many similar questions, yet still cannot find answer. how reference different class without initializing instance of it? how call "reloaddata" separate class reflect moc's data. moc seems saving have verified nsnotification.
popover class:
-(void)actionsave:(id)sender { maincontent *entitycontent = [nsentitydescription insertnewobjectforentityforname:@"maincontent" inmanagedobjectcontext:self.mdoc.managedobjectcontext]; entitycontent.date = [nsdate date]; entitycontent.title = self.titlename.text; //main question: how call viewcontroller's function in separate class? [viewcontroller reloadtableview]; //??? //separate question: how dismiss popover inside of function? }
viewcontroller class:
-(void)setuptable { self.tableview = [[uitableview alloc] initwithframe:cgrectmake(gridv1, 140, column1_width, 768-170) style:uitableviewstyleplain]; [self.tableview setbackgroundcolor:[uicolor clearcolor]]; self.tableview.autoresizessubviews = yes; self.tableview.delegate = self.tableviewcontroller; self.tableview.datasource = self.tableviewcontroller; [self.view addsubview:self.tableview]; } -(void)reloadtableview{ [self.tableview reloaddata]; }
tableviewcontroller class: (self.tableview's delegate , datasource)
- (void)setupfetchedresultscontroller { nsfetchrequest *request = [nsfetchrequest fetchrequestwithentityname:@"maincontent"]; // want sort them "date" attribute input [nsdate date]. request.sortdescriptors = [nsarray arraywithobject:[nssortdescriptor sortdescriptorwithkey:@"date" ascending:yes]]; // no predicate because want of data in "maincontent" entity. self.fetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:request managedobjectcontext:self.mdoc.managedobjectcontext sectionnamekeypath:nil cachename:nil]; } - (void)setmdoc:(uimanageddocument *)mdoc { if (_mdoc != mdoc) _mdoc = mdoc; } - (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; if (!self.mdoc) { [[globalmdoc shareddocumenthandler] performwithdocument:^(uimanageddocument *coredatabase) { self.mdoc = coredatabase; [self setupfetchedresultscontroller]; }]; } } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"overview cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier]; } maincontent *content = [self.fetchedresultscontroller objectatindexpath:indexpath]; cell.textlabel.text = content.title; cell.detailtextlabel.text = [nsstring stringwithformat:@"%d", [content date]]; return cell; }
okay make singleton example link: http://www.galloway.me.uk/tutorials/singleton-classes/
then make ivar in singleton uiviewcontroller uitableview in. in vdl of uitableview view,
[singleton sharedsingleton].theviewcontroller = self;
then in other view
singleton *singleton = [singleton sharedsingleton]; [singleton.mytableview reloaddata];
however, (= self) line, may want somewhere earlier applicationdidfinishlaunching theviewcontroller variable not nil when try access it.
Comments
Post a Comment