2011-01-31 10 views
0

2つの値を表示したい(1つは文字列、もう1つは整数)。

string1の00000 INT1
string2の00000 INT2
はstring3 00000 INT3セルの右側と2番目の左側の同じセルに2つの値を表示

0以下のような -
、私は同じセルに2つの値を表示する方法を知っている>スペース

をcell.textLabel.text = [NSString stringWithFormat:@ "%@ - %d"、[splitArrayValue objectAtIndex:row]、IntegerValue];

しかし

iが同じ行に2列で、この整数値を表示する
文字列1 00 INT1
文字列2 00000 INT2
はstring3 000 INT3
ない適切な整列に以下のようにその表示何か でありますそれは可能ですか?

は、あなたが自分のタグによってそれらを分化、細胞内に2 serparate UILabelsを追加する必要があり、事前に

答えて

1

をお願いします。

// 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

私はあなたに知らせてください、ありがとうございます – Pooja

+0

left.tag = kLeftLabel; right.tag = kRightLabel;これの必要性は何ですか? – Pooja

+0

これで、後で 'viewWithTag:'を呼び出すことができ、ラベルにアクセスすることができます。 – thelaws

0

また、以下のコードを使用することもできます。

2つの可変配列を言う取る - のviewDidLoadで配列1とアレイ2

を、配列を割り当て、両方の配列内の値を格納します。

(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; 

} 
関連する問題