ios - Can someone show me a more efficient way to handle multiple text field delegates? -
i'm working on project user have 5 text fields input data. "calculate" button calculates required computations based on user input. solution create 5 iboutlet uitextfields , connect them in xib file. each text field handle events based on input following code. can show me efficient way solve problem?
- (bool)textfieldshouldreturn:(uitextfield *)textfield{ if(textfield == self.numberofnightstf){ self.numberofnights = [self.numberofnightstf.text intvalue]; nslog(@"the number of nights set %.d days", self.numberofnights); } else if(textfield == self.nightlychargetf){ self.nightchargecost = [self.nightlychargetf.text floatvalue]; nslog(@"the cost of charge per night set %.2f$", self.nightchargecost); } else if(textfield == self.roomservicetf){ self.roomservicecost = [self.roomservicetf.text floatvalue]; nslog(@"the additional room service cost set %.2f$", self.roomservicecost); } else if(textfield == self.telephonetf){ self.telephonecost = [self.telephonetf.text floatvalue]; nslog(@"the additional telephone service cost telephone set %.2f$", self.telephonecost); } else if(textfield == self.misccosttf){ self.misccost = [self.misccosttf.text floatvalue]; nslog(@"the miscellaneous set %.2f$", self.misccost); } [textfield resignfirstresponder]; return yes;
}
there no real ineffiency in way you've handled already, approach other. real problem approach leads bloated viewcontroller classes when (this approach) applied multiple times.
as more experience in object oriented environments you'll learn mvc , state variables modifying here properties of model object rather self (assuming code in someviewcontroller) messages might self.model.telephonecost=..... etc.
Context Free Grammar
ReplyDeleteRegular Grammar
Ambiguity in Grammar
Chomsky Normal Form
Greibach Normal Form
Push Down Automata