Friday, 15 May 2015

ios - Exception thrown if string is null -


I'm getting an exception if a string is empty:

  Exceptions 'NSInvalidArgumentException' , Reason: '[NSNull length]: sent to unrecognized selector for example  

This is an object's object, which has an empty string:

 < Code> {cabdriver = "& lt; null & gt;"; Code = SV 1000000079; Date = "2015-03-15"; Fate = ""; Email = "jose@gmail.com"; Original = vxd; }  

And this is my code where an exception is thrown:

  - (UITableViewCell *) Table view: (UITableView *) tableView cellForRowAtIndexPath: ( NSIndexPath *) IndexPath {Historical celltel electricity cell * cell = (historial celltel vixel *) [Tableview Due Rewase Eligible cell wuth identifier: @ "cell"]; NSString * origin = [[[Historical Historian ObjectAttacks: IndexPath.ro] Valufei: @ "Basic"]; If (origin.length == 0) {cell.origen_label.text = @ "-"; } And {cell.origen_label.text = origin; } NSString * Destination = [[Historical Services ObjectAttex: IndexPath.ro] Valaphoriki: @ "Destination"]; If (destiny.length == 0) {cell.destiny_label.text = @ "-"; } Else {cell.destiny_label.text = Destination; } NSString * cabdriver = [[Historical Services ObjectOutindex: IndexPath.ro] Valufei: @ "Cabriver"]; If (cabdriver.length == 0) {cell.conductor_label.text = @ "-"; } And {cell.conductor_label.text = cabdriver; } NSString * date = [[[Historical Historian Objectiveindex: IndexPath.ro] Valufei: @ "Date"]; Cell.fecha_label.text = Date; Return cell; } I have tried other ways to check whether the string is empty or not, but I am searching and there should be a way to check it.  

Please tell me what is wrong with my code?

You should be prepared for any value from a server, so that's zero. I use the following two methods - to check a string, to check the second number:

  - string (NSString *) stringValueOfDictionaryObject: (id) dictionary object {if (dictionaryObject == [NSNull Null]] {return @ "";} and {return (NSString *) dictionary object;}} - (NSNumber *) Numeric VolUxinsons Object: (ID) dictionary object {if (dictionary object = [[NSL tap]) {return zero ;} And {return (NSNumber *) dictionary object;}}   
  NSString * cabDriver = [Self StringVollection Objective (ID) [[Historical Services ObjectiveIntex: IndexPath.ro] Valufecae: @ "Cabdrior"]];  

Note that if your CAB driver value is empty in your JSN file, then the above routine will return an empty string (@ ""). After or after your cab driver NSString value change to @ Are spun.


No comments:

Post a Comment