2011-09-30 6 views
0

내가보기에이 jQuery과에 봉착하고 난 단지 2 테이블 행 5 행 7스크롤 한 후 iOS UITableView 셀이 잘못로드됩니까?

에서 아슬하게 2 테이블을 스크롤 한 UITableViewCellAccessoryDisclosureIndicator을 추가 (행 1 사라지는) 다음 맨 위로 이동 (어느 행 1이 나타나는지), 행 1에는 이제 UITableViewCellAccessoryDisclosureIndicator가 있습니다! 행 1은 어떻게 든 행 5 또는 행 7이 되었습니까 ??? 아래는 cellForRowAtIndexPath 코드입니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    static NSString *CellIdentifier = @"Cell"; 

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

    cell.textLabel.textColor = [UIColor blueColor]; 
    cell.detailTextLabel.textColor = [UIColor blackColor]; 
    if (tableView == table1) 
    { 
     cell.textLabel.text = [title1 objectAtIndex:indexPath.row]; 
     cell.detailTextLabel.text = [list1 objectAtIndex:indexPath.row]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    else if (tableView == table2) 
    { 
     cell.textLabel.text = [title2 objectAtIndex:indexPath.row]; 
     cell.detailTextLabel.text = [list2 objectAtIndex:indexPath.row]; 
     if (indexPath.row == 5 || indexPath.row == 7) 
     { 
      cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
     } 
     else 
     { 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     } 
    } 
    return cell; 
} 

고마워요!

+0

그래서 당신이 서로 아래에 바로 위의 1 개보기 2 tableViews, /? 그렇다면 왜? – WrightsCS

+0

왜냐하면 나는 2 개의 테이블이 다른 너비를 갖기를 원합니다. 그렇지 않으면 2 개의 섹션이있는 1 개의 테이블을 사용할 것입니다. 다른 방법을 추천 해 주시겠습니까? 감사! – iceholder

답변

2

성능을 최적화하기 위해 UITableViewCell을 다시 사용합니다. 이것은 발생합니다 [tableView dequeueReusableCellWithIdentifier:CellIdentifier];tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 의 각 호출에서 셀에 원하는 모든 속성을 명시 적으로 설정해야합니다. 이 같은

뭔가 문제를 해결해야합니다

if (indexPath.row == 5 || indexPath.row == 7) 
     { 
      cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
     } 
     else 
     { 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
      cell.accessoryType = UITableViewCellAccessoryNone; 
     } 
+0

문제가 해결되었습니다. 답변 해주셔서 감사합니다 :) – iceholder

관련 문제