데이터베이스에 많은 항목을 나열하는 작은 응용 프로그램이 있습니다. 항목 중 하나를 클릭하면 해당 항목에 대한 모든 정보를 보여주는 새로운보기로 전환됩니다. 표시되는 정보의 양이 동적이기 때문에 두 번째보기를 UITableView로 만들고 표시되는 특정 객체에 대해 필요에 따라 각 행의 크기를 설정하여이 작업을 수행합니다. 일반적으로 정상적으로 작동하지만 항목 중 하나에 표시된 마지막 항목의 텍스트 월이 있습니다. 이 특정 객체에 대한 정보를 보려고하면 텍스트의 벽이 표시되어야하는 곳이 표시되지 않습니다.UITableViewCell이 텍스트를 표시하지 않습니다.
dubugging 동안 셀과 레이블이 있어야하는 크기를 결정하는 데 사용되는 텍스트를 올바르게 말할 수 있습니다. 그것은 정확하게 크기를 결정하는 것 같아요 (그것은 세포에 대한 21298과 레이블에 대한 21294의 높이를 제공합니다) 그리고 나는 다소 큰 빈 라벨로 보이는 것으로 스크롤 할 수 있습니다. 그러나 화면이 마치 상쾌한 것처럼 화면이 조금 엉망입니다. 뷰 위쪽의 텍스트는 화면의 처음부터 끝까지 시작하여 오른쪽의 스크롤 막대를 올바르게 다시 그리지 않습니다.
누구나 전에 이런 걸 본 적이 있습니까? 내가 충분히 담당자에게
편집을하지 않기 때문에
미안 해요, 내가 가지고있는 스크린 샷을 게시 할 수 없습니다 : 대답을 나타냈다. 최소 시간이 지나면 대답으로 게시 할 것입니다.
다른 사람이이 문제에 부딪 힐 경우 해결 방법을 찾았습니다.
주위를 파고 들자 소스 문자열 길이가 약 41,000이되면이 그리기 오류가 발생하기 시작합니다. 그래서 나는 ~ 30,000 이상의 모든 문자열을 분할하고 테이블에 여러 행을 추가했습니다. 이제 전체 텍스트 벽을 표시합니다.
코드 : 당신은 셀의 뷰 계층 구조를 구성하는 경우
[label setTag:[indexPath row]];
, 당신은 행 번호를 참조해서는 안됩니다 :
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 2.0f
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//static NSString *CellIdentifier = @"Cell";
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d", [indexPath row]];
UILabel *label = nil;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setMinimumFontSize:10.0];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setTag:1];
if ([indexPath row] == 1 || [indexPath row] == 2)
{
[label setTextColor:[UIColor redColor]];
}
else if ([indexPath row] == 3)
{
[label setTextColor:[UIColor colorWithRed:0.0f green:150.f/255.f blue:30.f/255.f alpha:1.0f]];
}
else if ([indexPath row] == 5)
{
[label setTextColor:[UIColor colorWithRed:155.f/255.f green:145.f/255.f blue:0.0f alpha:1.0f]];
}
[[cell contentView] addSubview:label];
}
NSString *text = [cardInfo objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN *2), 20000000000000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
if (!label)
{
label = (UILabel *)[cell.contentView viewWithTag:1];
}
[label setText:text];
[label setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN *2), MAX(size.height, 30.0f))];
// Configure the cell...
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *text = [cardInfo objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN *2), 20000000000000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 30.0f);
return height + (CELL_CONTENT_MARGIN * 2);
}
알아두면 좋을 것 같습니다. 그로 인해 다른 버그도 수정되었습니다. 감사 – rwakelan