2013-08-17 3 views
0

NSLayoutConstraints를 사용하는 사용자 지정/하위 클래스의 UITableViewCell이 있습니다. 가장 왼쪽에있는 UIImageView는 이미지로 채워지거나 채워지지 않을 수 있으며, 그렇지 않으면이 필드의 오른쪽에있는 객체는 자연스럽게 왼쪽으로 이동합니다. 사용자 지정 UITableViewCell 내에서 잘 작동하지만 내 사용자 지정 UITableViewController로 콘텐츠를 채울 예정입니다. 불행히도, 다음 코드는 모든 행 cell.dispatchedView에 이미지를 채 웁니다. 그러나 행을 채우지 않고 갇혀 있습니다.dequeueReusableCellWithIdentifier forIndexPath

이것은 dequeueReusableCellWithIdentifier와 관련이 있습니다. 아이디어?

static NSString *CellIdentifier = @"CellIdentifier"; 


- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self.tableView registerClass:[NXGActiveUnitsCell class] forCellReuseIdentifier:CellIdentifier]; 
} 

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

    NSDictionary *item = [self.model.dataSource objectAtIndex:indexPath.row]; 

    NXGActiveUnitsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    if([[[item objectForKey:@"cfs_no"] clean] length] > 0) { 
     cell.dispatchedView.image = [UIImage imageNamed:@"p.png"]; 
     NSLog(@">>>%@",[item objectForKey:@"cfs_no"]); 
    } else { 
     NSLog(@">>> i got nothing so I should not touch this row..."); 
    } 

    cell.departmentIconView.image = [UIImage imageNamed:@"f.png"]; 
    cell.unitLabel.text = [item valueForKey:@"unit_id"]; 

    return cell; 
} 
+0

if-else 문의 "else"부분을 입력하지 않았습니까? 그렇다면, self.model이 어떻게 보이는지 보여주기 위해 더 많은 코드를 추가해야합니다. – rdelmar

+0

실제로 'else'가 입력됩니다. 테이블 뷰를 아래로 스크롤하면 로그에 ">>> 아무 것도 없으므로이 행을 만지지 말아야합니다."라고 표시되는 것을 볼 수 있습니다. 그러나 아직 행의 이미지 "p.png"를 볼 수 있습니다. if 문을 주석 처리하면 모든 행에 "p.png"가 표시되지 않습니다. 나는 당황 스럽다. – caoimghgin

답변

2

이 이미 문제가 해결되는지 모르겠지만, 세포가 재사용되기 때문에 당신은 확실히의 다른-경우

cell.dispatchedView.image = nil; 

을 설정 한다.

+0

@ Martin_R. 세상에! 예! 그게 속임수 였어. – caoimghgin

관련 문제