2014-12-01 4 views
0

사용자 정의 셀이있는 UITableView가 있습니다. 레이블에 제약 조건을 추가 할 수 없어서 프로그래밍 방식으로이 작업을 시도했습니다. 이제는 스크롤을 시작할 때를 제외하고는 모든 것이 작동합니다. 어떻게 든 layoutsubviews 메서드는 무시되거나 재설정됩니다.스크롤시 사용자 정의 UITableViewCell 레이아웃

TableViewController.m

- (void) layoutSubviews { 
    [super layoutSubviews]; 
    CGSize screen = [UIScreen mainScreen].bounds.size; 
    [_subjectLabel setFrame:CGRectMake(15, 15, screen.width - 70, 20)]; 
} 
+0

대신'- (void) prepareForReuse' 메서드를 사용하려고 했습니까? – Astoria

답변

0

subjectLabel 공개적으로 액세스 할 수있게하고의 ViewController 자체 내에서의 프레임을 변경

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    SubjectCell *cell = (SubjectCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"]; 

    cell.subjectLabel.text = [tentamenArray objectAtIndex:currentRow][@"SUMMARY"]; 

    return cell; 
} 

SubjectCell.m.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    SubjectCell *cell = (SubjectCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"]; 

    cell.subjectLabel.text = [tentamenArray objectAtIndex:currentRow][@"SUMMARY"]; 

    CGSize screen = [UIScreen mainScreen].bounds.size; 
    [cell.subjectLabel setFrame:CGRectMake(15, 15, screen.width - 70, 20)]; 

    return cell; 
} 
관련 문제