2010-11-30 13 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タイプ012leを空の値となるでしょう – KingofBliss

+0

なぜアクセサリーすべてのデータと空のセルがありますあなたが行8の数を返し、それが呼び出される0から7の行だけを返すと静的です。 – Ishu

-1

cellForRowAtIndexPathメソッドでは、セルが再利用され、uスクロールするたびにindexpathが0から始まるため、NSLog(@ "Index Path.row =%d"、indexPath.row)コンソールウィンドウに表示されます。

+0

これは正しくありません。セルは再利用されますが、インデックスパスはゼロから再開されません。 – jsd

-1

...アルでませPRB ..私はuはので、各row..IfでindexPath.row印刷したいと思います

、uは次のように変更する必要がない私のために正常に動作してあなたのコード..

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

numberOfRowsInSection:が8以上を返しても、レピュテーションの機会はありません。

+0

実際には、細胞が再利用されるとすぐに、繰り返しがあるように見えます。後の行でセルを再利用すると、最初の8件だけが処理されるため、テキストはリセットされません。その場合のステートメントのデフォルトは何もせず、セルが最後に使用されたときのテキストを残します。 –

+0

あなたの解決策は問題を解決できません実際に問題は何かを印刷しない反復であり、反復は行数のためです。 – Ishu

+0

@Ishu:私は何か解決策を言っています。どうもありがとうございます。 – KingofBliss

関連する問題