objective c - else if change flow -


i have series of else if statements. check if data user enters valid. have text field user can enter title of deal. check make sure have entered something. want make sure have entered not white space.

as can see in code when user input not valid enter else if , exit method making sure deal not added.

however have problem. see if user has entered white space must first work out, inside else if.

effectively else if should along lines of 'if there white space enter else if , returned'. not possible don't know if there white space.

could flow in placed?

my else if expression must true if there white spaces.

your appreciated.

//checks if has been entered. space. if nothing entered length 0 , message displayed if (![self.dealtitletextfield.text length]> 0) {     nslog(@"deal title empty");     uialertview *alert = [[uialertview alloc]initwithtitle:@"not quite!" message:@"you haven't entered title , have have one. please so." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];     [alert show];     return ; }//start of new else entered 18th august , needs reworked else if ([self.dealtitletextfield.text length] > 0){     nscharacterset *charset = [nscharacterset whitespacecharacterset];     nsstring *trimmedstring = [self.dealtitletextfield.text stringbytrimmingcharactersinset:charset];     if ([trimmedstring isequaltostring:@""]) {         // string contains whitespace.         nslog(@"deal title made of white space");         uialertview *alert = [[uialertview alloc]initwithtitle:@"not quite!" message:@"you haven't entered title made purely of white space. isn't allowed." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];         [alert show];         return ;     }     nslog(@"deal title - end of check"); } //end of new else entered 18th august needs reworked else if (self.dealmodel.dealtypemodel == null){     nslog(@"deal type empty");     uialertview *alert = [[uialertview alloc]initwithtitle:@"not quite!" message:@"you haven't entered deal type , have have one. please so." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];     [alert show];     return; }else if (![self.dealdescriptiontextarea.text length]> 0){     nslog(@"deal textarea empty");//more code below not included out of scope 

trim white spaces first.

then need check length isn't 0.

don't differentiate between white spaces , nothing. on complicating user think. if enter white spaces clear nothing can type again.

also, third , fourth else if blocks should separate if statements.

three sets of ifs.

trim white space title. if deal title length 0 fail. if deal type null fail. if deal description blank fail. 

they not else ifs ifs.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -