2010-11-30 4 views
2

화면을 스크롤하면 반복되는 셀이 생깁니다. 이 문제를 어떻게 해결할 수 있습니까?내 UITableViewCell이 반복되는 이유는 무엇입니까?

// 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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    switch (indexPath.row) { 
     case 0: 
      cell.textLabel.text = [NSString stringWithFormat:@"Bar Cafe",indexPath.row]; 
      break; 
     case 1: 
      cell.textLabel.text = [NSString stringWithFormat:@"Boutique Hester",indexPath.row]; 
      break; 
     case 2: 
      cell.textLabel.text = [NSString stringWithFormat:@"Boutique Hester Shoes",indexPath.row]; 
      break; 
     case 3: 
      cell.textLabel.text = [NSString stringWithFormat:@"Local Advice - Paulina",indexPath.row]; 
      break; 
     case 4: 
      cell.textLabel.text = [NSString stringWithFormat:@"Museum Brileyeglass",indexPath.row]; 
      break; 
     case 5: 
      cell.textLabel.text = [NSString stringWithFormat:@"Redlight Swans",indexPath.row]; 
      break; 
     case 6: 
      cell.textLabel.text = [NSString stringWithFormat:@"Reefer Flying Dutchman",indexPath.row]; 
      break; 
     case 7: 
      cell.textLabel.text = [NSString stringWithFormat:@"Reefer Tiani Hempshop",indexPath.row]; 
      break; 

     default: 
      break; 
    } 

    // Configure the cell... 
    //cell.textLabel.text = [NSString stringWithFormat:@"Featured Event %d",indexPath.row]; 
    //cell.detailTextLabel.text = [NSString stringWithFormat:@"Description %d", indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 
+4

'tableView : numberOfRowsInSection :'return 8? 또한'indexPath.row'를'stringWithFormat :'에 전달하면 왜 사용되지 않을까요? – BoltClock

+0

우리는'-tableView : numberOfRowsInSection :'및'-numberOfSectionsInTableView :' – vikingosegundo

+0

누군가가 numberOfRowsInSection 주석을 답으로 게시 함을 보여줄 수 있습니다. 그것은 트릭을했다. –

답변

0
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 8; 
} 

당신이 반복 행의 8 개 이상의 다음 문제를 반환하는 경우이 numberOfRowsInSection 방법의 오른쪽 implementaion이다가 시작됩니다.

+0

그것은 prb를 해결할 수 없다 ... Plz는 코드를 올바르게 본다. 그는 마지막 라인에서만 accesoryType을 추가하고있다. 그래서 accesory 타입을 가진 빈 값이 atble이 될 것이다. – KingofBliss

+0

왜 모든 셀에 액세서리가있는 빈 셀이있을 것이다. 8 행의 수를 반환하면 정적 8 정적입니다. – Ishu

-1

cellForRowAtIndexPath 메서드에서 셀을 다시 사용하고 u 스크롤 할 때마다 indexpath가 0부터 시작합니다. 자세한 내용은 NSLog (@ "Index Path.row = % d", indexPath.row) 콘솔 창에 표시됩니다.

+0

올바르지 않습니다. 셀은 재사용되지만 인덱스 경로는 0에서 다시 시작되지 않습니다. – jsd

-1

... 알에서 어떤 PRB .. 내가 u는 각각의 row..If에서 indexPath.row 인쇄 할 생각

, u는 다음과 같이 변경할 필요가 없습니다 나를 위해 잘 작동 코드를 입력하십시오 ..

[NSString stringWithFormat:@"Reefer Tiani Hempshop %d",indexPath.row]; 

numberOfRowsInSection :이 8을 초과하는 경우에도 평판의 기회는 없습니다.

+0

실제로, 세포가 재사용 되 자마자 반복되는 것처럼 보입니다. 이후 셀에서 셀을 다시 사용할 때 처음 8 개의 경우 만 처리되기 때문에 텍스트가 다시 설정되지 않기 때문입니다. 이 case 문에서 기본값은 셀을 마지막으로 사용한 텍스트를 그대로두고 아무 일도하지 않습니다. –

+0

당신의 솔루션은 문제를 실제로 해결할 수 없습니다. 문제는 반복적으로 어떤 것이 든 인쇄되지 않고 반복이 행 수 때문입니다. – Ishu

+0

@ 이슈 : 어떤 해결책이라도 ........ 정확히 읽으십시오. – KingofBliss

관련 문제