iPhone 장치 3.1 SDK는 UitableViewCellStyleValue1 TextLabel의 수직 정렬 중단

StackOverflow https://stackoverflow.com/questions/1408105

  •  05-07-2019
  •  | 
  •  

문제

누구든지 다음 현상에 대한 설명을 제공 할 수 있습니까?

iPhone 장치 3.1 SDK에서 UITableViewCell 스타일입니다 UITableViewCellStyleValue1 그리고 그것 detailTextLabel.text 할당되지 않은 다음 textLabel 예상대로 셀의 중앙에 표시되지 않습니다.

주목할만한 경고 중 하나는 이것이 내가 테스트 할 때만 발생한다는 것입니다. 장치 - iPhone 모의 실험 장치 3.1 SDK는 셀을 올바르게 표시합니다. 또한 iPhone 장치 3.0 SDK를 사용할 때는 문제가되지 않습니다.

아래는 간단합니다 UITableViewController 문제를 보여주는 서브 클래스 구현.

@implementation BuggyTableViewController

#pragma mark Table view methods


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }

    switch (indexPath.row) {
  case 0:
   cell.textLabel.text = @"detailTextLabel.text unassigned";
   break;
  case 1:
   cell.textLabel.text = @"detailTextLabel.text = @\"\"";
   cell.detailTextLabel.text = @"";
   break;
  case 2:
   cell.textLabel.text = @"detailTextLabel.text = @\"A\"";
   cell.detailTextLabel.text = @"A";
   break;
  default:
   break;
 }

    return cell;
}

@end
도움이 되었습니까?

해결책

대신에

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

사용해보십시오

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

다른 팁

나는 또한 같은 문제가있었습니다. 셀은 시뮬레이터에서 잘 보였지만 장치에서 앱을 실행했을 때 셀 텍스트는 수직으로 중앙에 있지 않았습니다. uitableviewcellstyledefault를 사용하면 수직 정렬 중심 문제가 해결되었습니다. 다행히 내 셀에는 자막이 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top