ios - Exception while showing data from dictionary on custom cell -


i have dictionary having following details

{     name = "american airlines";     picture =         (             ""     );     rate = 3;   }, 

and want show name on label of cell...for doing following code:

-(void)viewwillappear:(bool)animated {     [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(getdetail:) name:@"newnotification" object:nil];  }  -(void)getdetail:(nsnotification *)notification {      if([notification.name isequaltostring:@"newnotification"])     {         nsdictionary *dictionary=notification.userinfo;         nslog(@"dictionary  %@",dictionary);         userinfo=dictionary;         [self.listview reloaddata];      }   }   -(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{     //return  [userinfo count];     return 115; } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{      static nsstring *cellidentifier=@"cell";      tableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell== nil) {          cell = [[tableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }      cell.name.text =[userinfo valueforkey:@"name"];      nslog(@"the cell.name.text %@",cell.name.text);     //[cell updatecell:userinfo];      return cell;  } -(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     return 75;  } 

i can't understand i'm doing wrong in code crashes , doesn't show on label.it give exception

"terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsarrayi length]: unrecognized selector sent instance 0x7bea2d20'"

please check code , tell me going wrong!

in code there parsing issue. take global array in class called arrlist. please update code

if([notification.name isequaltostring:@"newnotification"])     {         nsdictionary *dictionary=notification.userinfo;         nslog(@"dictionary  %@",dictionary);         userinfo=dictionary;         [self.listview reloaddata];      } 

with one:

if([notification.name isequaltostring:@"newnotification"])         {             nsdictionary *dictionary=notification.userinfo;             nslog(@"dictionary  %@",dictionary);             [arrlist addobject: dictionary];             [self.listview reloaddata];          } 

when call webservice, array add dictionary.

now change line of code tableview:

-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{     //return  [userinfo count];     return 115; } 

with one:

-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{          return [arrlist count];     } 

and adding few lines of code in tableview method cellforrowatindexpath:

-(uitableviewcell *)tableview:(uitableview *)tableview        cellforrowatindexpath:(nsindexpath *)indexpath{      static nsstring *cellidentifier=@"cell";      tableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      if (cell== nil) {           cell = [[tableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }    if(arrlist.count > 0){       nsdictonary * dict = arrlist[indexpath.row];       cell.name.text =[dict valueforkey:@"name"];        nslog(@"the cell.name.text %@",cell.name.text);       //[cell updatecell:userinfo];     }      return cell; 

}

now fix crash.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -