2011-01-31 35 views
0

我想显示两个值(一个是字符串,另一个是整数)。
像以下
字符串1 00000 INT1
字符串2 00000 INT2
STRING3 00000 INT3在单元的右侧和左侧显示同一单元格上的两个值

0 - >空间

我知道如何在同一单元格中显示2个值,
cell.textLabel.text = [NSString stringWithFormat:@“%@ - %d”,[splitArrayValue objectAtIndex:row],IntegerValue];

但其显示类似以下
字符串1 00 INT1
字符串2 00000 INT2
STRING3 000 INT3
没有正确对齐

我想在同一行显示第2列该整型值 是可能吗?

预先感谢您

回答

1

您应该增加两个serparate UILabels进入细胞内,通过他们的标签区分它们。

// tableView:cellForRowAtIndexPath 
// ... 
if (cell == nil) { 
    cell = [[[UITableViewCEll alloc] init] autorelease]; 

    CGRect leftF = CGRectMake(10, 5, 100, 30); 
    CGRect rightF = CGRectMake(120, 5, 100, 30); 

    UILabel * left = [[[UILabel alloc] initWithFrame:leftF] autorelease]; 
    left.tag = kLeftLabel; // assumming #define kLeftLabel 100 

    [cell.contentView addSubview:left]; 

    UILabel * right = [[[UILabel alloc] initWithFrame:rightF] autorelease]; 
    right.tag = kRightLabel; // assumming #define kRightLabel 101 

    [cell.contentView addSubview:right]; 
} 

UILabel * leftLabel = (UILabel*)[cell.contentView viewWIthTag:kLeftLabel]; 
UILabel * rightLabel = (UILabel*)[cell.contentView viewWIthTag:kRightLabel]; 

// now put your two values in these two distinct labels 
+0

我会尝试n让你知道,谢谢 – Pooja 2011-01-31 15:28:30

0

您也可以使用下面的代码。希望它可以帮助。

取2个可变阵列说 - ARRAY1和阵列2

在viewDidLoad中,分配的阵列和值存储在两个阵列。

(void)viewDidLoad 
{ 

    array1=[NsMutableArray alloc]init]; 
    [array1 addObject:@"string1"]; 
    [array1 addObject:@"string2"]; 
    [array1 addObject:@"string3"]; 

    array2=[NsMutableArray alloc]init]; 
    [array2 addObject:@"int1"]; 
    [array2 addObject:@"int2"]; 
    [array2 addObject:@"int3"]; 
} 

然后继续使用cellForRowAtIndexPath中的代码。

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2   reuseIdentifier:CellIdentifier] ; 
    } 

    cell.textLabel.text =[array1 objectAtIndex:indexPath.row]; 

    cell.detailTextLabel.text =[array2 objectAtIndex:IndexPath.row]; 

    return cell; 

} 
相关问题