ios - Why my custom protocol is not being call? Objective - C -


i have 2 vc, 1 users write data, textfield or pickerview, , main screen show data on tableview. problem when click on done button, might call delegate, on first vc, implemented, doesnt receive call. should do? have been 2 days trying find bug, , nothings happens. help.

2vc.h

@protocol addcountrydelegate <nsobject>  @required  -(void)didcreatecountry:(countryclass*)country;  @end  @interface addcountryviewcontroller : uiviewcontroller  @property (assign, nonatomic) id<addcountrydelegate> customdelegate; 

2vc.m

- (ibaction)actiondone:(id)sender {      nsstring* itemname = self.itemnametextfield.text;     nsstring* countryname = self.countrynametextfield.text;     nsdate *countrydate = [datepickerview date];     nsstring *daysleftstring = [nsstring stringwithformat:@"%@ days", self.dayslefttextfield.text];      nsinteger daysleftint = [daysleftstring integervalue];      nsnumber *daysleft = [nsnumber numberwithinteger:daysleftint];      nsstring *paymentmethod = self.paymentmethodtextfield.text;      countryclass* newcountryitem =     [[countryclass alloc] initwithcountryname:countryname countrylogo:@"" itemname:itemname countrydate:countrydate daysleft:daysleft andpaymentmethod:paymentmethod];      [self.customdelegate didcreatecountry:newcountryitem];      [self dismissviewcontrolleranimated:yes completion:nil];   } 

and implementation on 1st vc:

-(void)didcreatecountry:(countryclass *)country{      //add new country-itemcountry - updating our model data      nsmutablearray *mutablecountries = [self.countries mutablecopy];      [mutablecountries addobject:country];      self.countries = [mutablecountries copy];      //updating view      [self.tableview reloaddata];      nslog(@"created");      [self savecountriestodisc];  }  -(void)savecountriestodisc{      nsmutablearray* convertedcountries = [nsmutablearray array];      //converting model dictionary      for(countryclass *country in self.countries)     {         nsdictionary *convertedcountry = [shop countriestodictionary];         [convertedcountries addobject:convertedcountry];     }      //now convertedshows contains strings, numbers,     //arrays , dictionary     nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);      nsstring *documentsdirectory = paths.firstobject;      nsstring *destinationpath = [documentsdirectory stringbyappendingpathcomponent:@"countrieslistdata.plist"];      //now tell array save     [convertedcountries writetofile:destinationpath atomically:yes];      nslog(@"saved");      [self.tableview reloaddata];  } 

i initialize delegate on prepareforsegue

-(void)prepareforsegue:(uistoryboardsegue *)segue                 sender:(id)sender {         if ([segue.identifier isequaltostring:@"addsegue"]) {              addcountryviewcontroller* addcountryvc =             segue.destinationviewcontroller;             addcountryvc.customdelegate = self;      } 

where in vc1 did set customdelegate self?

also should set delegate weak not assign


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -