기본적으로 자동보기 사용자 정의 테이블보기 셀을 사용하여 테이블보기에 데이터를 표시하고 크기를 완벽하게 조정합니다. 셀에 데이터를 표시하려면 UILabel
이 있고 장치 텍스트 크기가 변경되면 셀에 자동 크기가 지정됩니다. 나는 때때로 UILabel
의 모든 텍스트를 보여주기 위해 셀 자동 크기 지정에 문제가 있습니다. 예를 들어 텍스트 크기가 중간 크기 인 경우 긴 레이블의 모든 텍스트를 완전히 표시하지 않는 경우가 대부분이며 "..."표시가되지만 텍스트 크기를 늘리거나 줄이면 그것은 모든 것이지만 다른 세포에 대해서도 똑같은 일을 할 수 있습니다.iOS 8 - 자동 크기 조절 셀이 항상 모든 라벨 텍스트를 표시하지는 않습니다.
제안 사항?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
_cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (_cell == nil)
{
_cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
PFObject *object = [_postsArray objectAtIndex:indexPath.row];
NSString *nameString = [object objectForKey:@"Name"];
_cell.cellLabel.text = [NSString stringWithFormat:@"Posted by %@", nameString];
_cell.cellPostLabel.text = [NSString stringWithFormat:@" %@", [object objectForKey:@"Post"]];
//The following lines are to auto resize when the text size is changed
_cell.cellLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
_cell.cellPostLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
return _cell;
}
레이블이 멀티 라인 있습니까? – jszumski
그들은 있습니다. 셀 높이는'_cell.cellPostLabel'의 높이 (선의 양)에 따라 자동으로 결정됩니다. 라벨은 다른보기 컨트롤러에서 작성되었으며 최대 문자 크기가 199이므로 지나치게 길지 않은 게시물을 표시합니다. – kyle
수정 : 여러 줄로 표시 할 수 있으며 텍스트의 양에 따라 다릅니다. 일부는 그렇지 않을 수도 있습니다. – kyle