2011-01-31 2 views
0

두 개의 값을 표시하려고합니다 (하나는 문자열이고 다른 하나는 정수임).
문자열 1 00000 INT1
문자열 2 00000 INT2
string3 00000 INT3두 셀의 값을 같은 셀에 표시합니다. 셀의 오른쪽과 두 번째 왼쪽에 하나씩

0 다음과 같은
- i가 동일한 셀에 2 개 값을 표시하는 방법을 알고

> 공간을,
cell.textLabel.text = [NSString stringWithFormat : @ "% @ - % d", [splitArrayValue objectAtIndex : row], IntegerValue];

하지만

제가 동일한 행 2 열이 정수 값을 표시 할
문자열 1 00 INT1
문자열 2 00000 INT2
string3 000 INT3
하지 적절한 정렬을 다음과 같이 그것의 표시 일 은 가능한가?

당신은 자신의 태그로 그들을 차별화, 셀에 두 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; 

} 
관련 문제