ios - [UIBarButtonItem _isAncestorOfFirstResponder]: unrecognized selector sent to instance -
this code works in 1 app , crashes in message:
[uibarbuttonitem _isancestoroffirstresponder]: unrecognized selector sent instance
if comment magical record code can see method runs ok.
- (void)viewdidload{ [super viewdidload]; uibarbuttonitem *addbutton = [[uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self action:@selector(addnote:)]; self.navigationitem.rightbarbuttonitem = addbutton; } - (ibaction)addnote:(id)sender{ nslog(@"%s",__pretty_function__); nsmanagedobjectcontext *localcontext = [nsmanagedobjectcontext mr_contextforcurrentthread]; note *note = [note mr_createincontext:localcontext]; nsdate *now = [nsdate date]; note.date = now; note.person = _person; [localcontext mr_savewithoptions:mrsavesynchronously completion:^(bool success, nserror *error) { uistoryboard *sb = [uistoryboard storyboardwithname:nsbundle.mainbundle.infodictionary[@"uimainstoryboardfile"] bundle:nsbundle.mainbundle]; noteviewcontroller *vc = [sb instantiateviewcontrollerwithidentifier:@"noteviewcontroller"]; vc.note = note; [self.navigationcontroller pushviewcontroller:vc animated:yes]; }]; } - (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; uilabel *noresultslabel = [[uilabel alloc]initwithframe:cgrectmake(0, 0, self.tableview.bounds.size.width, self.tableview.bounds.size.width)]; noresultslabel.textcolor = [uicolor colorwithwhite:0.557 alpha:1.000]; noresultslabel.font = [uifont boldsystemfontofsize:35]; noresultslabel.textalignment = nstextalignmentcenter; noresultslabel.text = nslocalizedstring(@"no notes", nil); self.tableview.nxev_emptyview = noresultslabel; self.fetchedresultscontroller.delegate = self; [self.fetchedresultscontroller performfetch:nil]; [self.tableview reloaddata]; } - (void)viewwilldisappear:(bool)animated { [super viewwilldisappear:animated]; _fetchedresultscontroller.delegate = nil; } #pragma mark - fetched results controller - (void)dealloc { nslog(@"%s",__pretty_function__); self.fetchedresultscontroller.delegate = nil; self.fetchedresultscontroller = nil; } - (nsfetchedresultscontroller *)fetchedresultscontroller { if (_fetchedresultscontroller != nil) { return _fetchedresultscontroller; } nspredicate *predicate = [nspredicate predicatewithformat:@"person == %@", _person]; self.fetchedresultscontroller = [note mr_fetchallgroupedby:@"source" withpredicate:predicate sortedby:@"source,date" ascending:yes delegate:self]; nserror *error = nil; if (![self.fetchedresultscontroller performfetch:&error]) { nslog(@"unresolved error %@, %@", error, [error userinfo]); abort(); } return _fetchedresultscontroller; } - (void)controllerwillchangecontent:(nsfetchedresultscontroller *)controller { [self.tableview beginupdates]; } - (void)controller:(nsfetchedresultscontroller *)controller didchangesection:(id <nsfetchedresultssectioninfo>)sectioninfo atindex:(nsuinteger)sectionindex forchangetype:(nsfetchedresultschangetype)type { switch(type) { case nsfetchedresultschangeinsert: [self.tableview insertsections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangedelete: [self.tableview deletesections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade]; break; } } - (void)selectcreatedrowatindexpath:(nsindexpath *)indexpath{ [self.tableview selectrowatindexpath:indexpath animated:yes scrollposition:uitableviewscrollpositionmiddle]; } - (void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type newindexpath:(nsindexpath *)newindexpath { uitableview *tableview = self.tableview; switch(type) { case nsfetchedresultschangeinsert: [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationautomatic]; break; case nsfetchedresultschangedelete: [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationautomatic]; break; case nsfetchedresultschangeupdate: [self configurecell:(notecell *)[tableview cellforrowatindexpath:indexpath] atindexpath:indexpath]; break; case nsfetchedresultschangemove: [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationautomatic]; [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath]withrowanimation:uitableviewrowanimationautomatic]; break; } } - (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller { [self.tableview endupdates]; [self.tableview reloaddata]; } - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section{ id <nsfetchedresultssectioninfo> sectioninfo = [self.fetchedresultscontroller sections][section]; if (sectioninfo.name.intvalue == 0) { return nslocalizedstring(@"not secret", @"notes"); }else return nslocalizedstring(@"secret", @"notes"); } - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return [[self.fetchedresultscontroller sections] count]; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { id <nsfetchedresultssectioninfo> sectioninfo = [[self.fetchedresultscontroller sections] objectatindex:section]; return [sectioninfo numberofobjects]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"note cell"; notecell *cell = (notecell *)[tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; [self configurecell:cell atindexpath:indexpath]; return cell; } - (void)configurecell:(notecell *)cell atindexpath:(nsindexpath *)indexpath { note *note = [self.fetchedresultscontroller objectatindexpath:indexpath]; cell.datelabel.text = [[czdateformattercache mainqueuecache] localizedstringfromdate:note.date datestyle:kcfdateformatterlongstyle timestyle:kcfdateformattershortstyle]; if (note.note.length > 0) { cell.notelabel.text = note.note; } else { cell.notelabel.text = nslocalizedstring(@"new note", nil); } cell.rateview.rate = [note.trustworthy intvalue]; nslog(@"note.trustworthy intvalue %i", [note.trustworthy intvalue]); cell.rateview.backgroundcolor = [uicolor clearcolor]; cell.backgroundcolor = [uicolor whitecolor]; } - (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath { if (editingstyle == uitableviewcelleditingstyledelete) { [magicalrecord saveusingcurrentthreadcontextwithblock:^(nsmanagedobjectcontext *localcontext) { [[self.fetchedresultscontroller objectatindexpath:indexpath] mr_deleteincontext:localcontext]; } completion:^(bool success, nserror *error) { // }]; } } - (bool)tableview:(uitableview *)tableview canmoverowatindexpath:(nsindexpath *)indexpath { return no; } #pragma mark - segue - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"note segue"]) { nslog(@"%s",__pretty_function__); nsindexpath *indexpath = [self.tableview indexpathforselectedrow]; note *note = [[self fetchedresultscontroller] objectatindexpath:indexpath]; noteviewcontroller *anvc = segue.destinationviewcontroller; anvc.note = note; } }
ok, problem in second view controller. found occasionally.
i used uibarbuttonitem
custom view navigation bar titleview
.
Comments
Post a Comment