多个UITableViewCell中的多个数组

时间:2012-12-26 06:15:29

标签: iphone ios ipad

我知道如何在UITableViewCell中获取数组:

cell.textLabel.text=[NSString stringWithFormat:@"%@",array];

但是如何将不同的数组放在多个UITableViewCell

Like first cell: array.

secondcell:array1

thirdcell: array2.

以及如何在每个单元格中制作多条线, 应该是这样的:

A

B

C

D

UItableViewCell

1 个答案:

答案 0 :(得分:0)

你可以在不同的单元格中添加不同数组中的值,如下所示。另外我在UITableCell添加控件只是一个例子,通过你可以在框架中添加多个控件...

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {    
         static NSString* cellIdentifier = @"gridCell";

        UITableViewCell *yourCell = [tableView dequeueReusableCellWithIdentifier:nil];

        if(yourCell == nil)        
        {
            yourCell =  [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];

        }

        if(indexPath.row == 0)        
        {
          yourCell.textLabel.text=[NSString stringWithFormat:@"%@",array];
          UILabel *lbl = [[UILabel alloc]init];
          lbl.text = [NSString stringWithFormat:@"%@",array];
          lbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
          [lbl setFrame:CGRectMake(110, 5, 200, 31)];    /// Set Frame which you want for every controls...
          // you can also add UITextView,etc..
          [yourCell.contentView addSubview:lbl];

         UILabel *lbl2= [[UILabel alloc]init];
          [lbl2 setFrame:CGRectMake(110, 31, 200, 31)];        
          lbl2.text = [NSString stringWithFormat:@"%@",array1];
          lbl2.font = [UIFont fontWithName:@"Helvetica" size:12];

         lbl2.textColor = [UIColor darkGrayColor];

         [yourCell.contentView addSubview:lbl2];
        }
        else if(indexPath.row == 1)        
        {
          yourCell.textLabel.text=[NSString stringWithFormat:@"%@",array1];
          ///ADD also Controls here if you want to in this cell also...or every cell also then write and add subview outside from this if condition

        }
        else if(indexPath.row == 2)        
        {
          yourCell.textLabel.text=[NSString stringWithFormat:@"%@",array2];
        }

        return yourCell;
    }

如果你想在一个单元格中添加多行,那么只需添加UILable或任何其他控件并设置框架并添加为单元格的子视图,并使用波纹管方法设置单元格的高度...

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ 
    //height of table row
    return 80;///give the height to cell which you want here
}