次のように、別のセルの別の配列から値を追加でき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;
}
そして、1つのセルに複数の行を追加したい場合は、UILable
または他のコントロールを追加してフレームを設定し、セルのサブビューとして追加し、次の方法でセルの高さを設定します...
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//height of table row
return 80;///give the height to cell which you want here
}