2011-12-01 3 views
0

특정 indexPath.row에서 셀의 레이블 하나의 너비를 줄이려고합니다.하지만 작동하지 않습니다. 아래 코드는 iOS 5 스토리 보드를 사용하고 있습니다. 런타임에 레이블의 크기를 변경하는 다른 방법이 있습니까?iOS 5의 tableView에있는 사용자 정의 셀

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"name&email"]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 


} 
UILabel *nameLabel = (UILabel *)[cell viewWithTag:100]; 
UILabel *detail = (UILabel *)[cell viewWithTag:101]; 
if(indexPath.row == 0){ 
    nameLabel.text = @"Name : "; 
    detail.text = @""; 
}else if(indexPath.row == 1){ 
    nameLabel.text = @"Email : "; 
    detail.text = @""; 
}else if(indexPath.row == 2){ 
    nameLabel.text = @"Location Alerts"; 
    detail.text = @"Notifies people when they are close to a saved spot"; 
// here i am changing the width of lable 
    detail.frame = CGRectMake(0, 0, 100, 0); 
}else if(indexPath.row == 3){ 
    nameLabel.text = @"Share This App :"; 
    detail.text = @"(post to facebook/twitter)"; 
}else if(indexPath.row == 4){ 
    nameLabel.text = @"Review This App :"; 
    detail.text = @"(on iTunes)"; 
}else if(indexPath.row == 5){ 
    nameLabel.text = @"Get Help :"; 
    detail.text = @"(send an email to me)"; 
} 
// Configure the cell... 

return cell; 
} 

답변

0

저는 전문가는 아니지만 두 가지 식별자를 사용하고 있습니다. 내가 당신이라면

나는 시도 할 것이다 :

static NSString *CellIdentifier = @"name&email"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"name&email"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 


    } 

확인? 작동하는지 알려주십시오.

0

Storyboard에서 사용자 정의 셀을 만든 경우 식별자이 무엇인지 확인하고 사용하십시오. 식별자속성 검사기 아래에 있어야합니다. 식별자가 인 경우 인 경우 코드는 다음과 같이 셀을 가져와야합니다. 당신이 UILabel의 당신의 너비를 변경하려면 세부라는있는 경우

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

, 당신은 프레임을 변경하고 이전 프레임 기원크기의 높이를 재사용하여 크기를 변경할 수 있습니다.

detail.frame = CGRectMake(detail.frame.origin.x, detail.frame.origin.y, newWidth,detail.frame.size.height); 

같은 높이를 유지하기 위해 높이로 detail.size.height 합격 확인은 (나는 높이가 표시되지 아니하는 영입니다 귀하의 예제에서 발견). 희망은 도움이