您可以在不同的单元格中添加来自不同数组的值,如下所示.. 另外我添加控件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
}