자동 크기 조정 테이블보기 셀에 문제가 있습니다. 텍스트의 양에 따라 셀의 레이블 크기를 조정할 수 있었지만 적절하게 셀 높이를 조정할 수는 없습니다. iOS - 자동 크기 조정 테이블보기 셀
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
_cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
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:@"PostedDream"]];
[_cell.cellPostLabel sizeToFit];
[tableView setAutoresizesSubviews:YES];
NSLog(@"cell post label height: %f", _cell.cellPostLabel.frame.size.height);
return _cell;
}
상황이주의해야 할
내가UITableViewCell
에서 서브 클래스
TableViewCell *cell
라는 사용자 지정 테이블 뷰 셀과 셀을 사용하고 그 레이블 IB를 통해 추가 된 있습니다 여기에 몇 가지 코드입니다. 조정중인 레이블은 cellPostLabel이며 텍스트 양에 따라 완벽하게 조정되지만 셀이 조정되지 않아 잘릴 수 있습니다. 또한
[self.tableView setAutoresizesSubviews:YES];
과
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
을
viewDidAppear:
에 전화를 걸었지만 아무 것도 시도하지 않았습니다. 모든 제안을 부탁드립니다.
세포는 iOS 8을 제외하고는 크기가 조정되지 않습니다.이 iOS 8은 맞습니까? iOS 8에서 자체 크기 조정 셀이 작동하는 방식을 이해합니까? 자체 크기 조정을 발생시키는 코드에서는 아무 것도하지 않습니다. – matt
그런데 왜'dequeueReusableCellWithIdentifier :'라고 부르니? 그건 아이폰 OS 6부터 오래된 것입니다. 당신은'dequeueReusableCellWithIdentifier : forIndexPath :'를 사용해야합니다. – matt
그래서'[self.tableView setAutoresizesSubviews : YES];와'self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;'줄이 있습니다. 일하지 않았지만 시도였습니다. 몇 달 전에 새로운 버전의 버그로 2 달 렸기 때문에 iOS 7을 사용하고 Xcode의 최신 버전을 실행하지 않았으므로 다운 그레이드하고 다시 업그레이드하지 않으려 고했습니다. 또한 좀 더 새로운 프로그래머. 그리고 나는'dequeueReusableCellWithIdentifier : forIndexPath :'로 전환했다. 크기 조정이 8보다 이전 버전에서 어떻게 수행되는지 알고 싶습니다. – Kyle