Sunday, 25 September 2011

Testing for sting in UITextField


i ran in problems tonight testing see if there string in textfield. can test see if textfield empty or need copy value in nsstring first test it? textfield empty evaluates true , executes if statement.

code:
-(void)closeentry{      nslog(@"the amount textfield: %@", amounttextfield.text); // test        [color="red"] if (![amounttextfield.text isequaltostring:@""]) [/color]{          entryamount = [amounttextfield.text floatvalue];          nsstring *floatconversion = [nsstring stringwithformat:@"$ %@.02f", entryamount];          entrystring = worktypetextfield.text;                    nsdictionary *tempdict = [[nsdictionary alloc] initwithobjectsandkeys:floatconversion,@"entryamount",entrystring,@"entrydiscription", nil];                    [tableviewarray addobject:tempdict];          nslog(@"tabelviewarray %@", tableviewarray);                    totalincome = 0.0;          (int = 0; < [tableviewarray count]; i++) {              nsmutabledictionary *tempincomedict = [[nsmutabledictionary alloc] initwithdictionary:[tableviewarray objectatindex:i]];              nslog(@"tempincomedict %@", tempincomedict);              nsstring *tempstring = [nsstring stringwithformat:@"%@", [tempincomedict objectforkey:@"entryamount"]];                            totalincome = totalincome + [tempstring floatvalue];          }          total.text = [nsstring stringwithformat:@"%.02f",totalincome];          [self.tableview reloaddata];                }     [enteryview removefromsuperview];  }  
 

what output nslog()? it's not null, it? because null isn't empty string.

output if nslog text property's length?

have considered possibility text property contains 1 or more spaces? string of spaces appear empty when nslog'ed, yet not equal @"".

why don't try way said: text property nsstring* variable , test there. in short: try it, see happens.

having text in variable make easier inspect in debugger, too. if don't know how use debugger, time learn.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment