0

NSDictionarycell Array の代わりに使用したい。

以下は私のコードです:

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

         UITableViewCell *cell=[[UITableViewCell alloc]  initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
        //Add the Bg Image to the cell
         //Add the 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;

       }
4

2 に答える 2

0
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];

今 cellForRowAtIndexPath で:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

     UITableViewCell *cell=[[UITableViewCell alloc]  initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    //Add the Bg Image to the cell
     //Add the 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;

   }

numberOfRowsInSection にも:

   -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section   
   {
       return [array count];
   }
于 2013-05-04T07:32:15.277 に答える