iphone - How to set Title for cell using Dictionary -


i want use nsdictionary instead of cell array.

following code:

     - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{           uitableviewcell *cell=[[uitableviewcell alloc]  initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell"];         //add bg image cell          //add label          uilabel *celltitle=[[uilabel alloc]initwithframe:cgrectmake(15, 7, 300, 30)];          [celltitle setbackgroundcolor:[uicolor clearcolor]];          [celltitle setfont:[uifont fontwithname:@"helvetica-bold" size:12]];          [celltitle settextcolor:[uicolor darkgraycolor]];          [celltitle settext:[[cellarray objectatindex:indexpath.section]             objectatindex:indexpath.row]];          [cell.contentview addsubview:celltitle];          return  cell;         } 

nsdictionary *dictionary1 = [[nsdictionary alloc] initwithobjectsandkeys:@"abc",@"name",@"12",@"age", nil];  nsdictionary *dictionary2 = [[nsdictionary alloc] initwithobjectsandkeys:@"def",@"name",@"14",@"age", nil];  nsdictionary *dictionary3 = [[nsdictionary alloc] initwithobjectsandkeys:@"ghi",@"name",@"16",@"age", nil];  nsdictionary *dictionary4 = [[nsdictionary alloc] initwithobjectsandkeys:@"jkl",@"name",@"18",@"age", nil];  nsarray *array = [[nsarray alloc] initwithobjects:dictionary1,dictionary2,dictionary3,dictionary4, nil]; 

now in cellforrowatindexpath:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{       uitableviewcell *cell=[[uitableviewcell alloc]  initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell"];     //add bg image cell      //add label      uilabel *celltitle=[[uilabel alloc]initwithframe:cgrectmake(15, 7, 300, 30)];      [celltitle setbackgroundcolor:[uicolor clearcolor]];      [celltitle setfont:[uifont fontwithname:@"helvetica-bold" size:12]];      [celltitle settextcolor:[uicolor darkgraycolor]];      [celltitle settext:[[array objectatindexpath:indexpath.row] objectforkey:@"name"]];      [cell.contentview addsubview:celltitle];      return  cell;     } 

also in numberofrowsinsection:

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

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -