2012-02-09 44 views
0

我正在開發一個iPhone應用程序,並且在檢查分組tableview的部分時遇到了一些麻煩。當第一部分不再可見時,因爲我向下滾動了tableview並且tableview彈回了,第二部分從第一部分獲取設置?我使用indexPath.section值來檢查它是哪一部分。我該如何解決這個問題?對不起,如果我的英語不正確!UITableView部分當上一部分不在屏幕上iPhone

抱歉缺少代碼! 這裏是一塊的cellForRowAtIndexPath代碼:

- (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]; 
    } 
    if(indexPath.section == 0){ 
     pinSwitch.hidden = YES; 
    cell.imageView.image = [UIImage imageNamed:@"test_item.png"]; 
    if([headarray count] != 0){ 
     if(indexPath.row > [headarray count] - 1){ 
      cell.imageView.alpha = 0; 
      cell.textLabel.text = [NSString stringWithFormat:@"Add new",indexPath.row + 1]; 

     } 
     else{ 
      cell.imageView.alpha = 1; 
      NSArray *infoarray = [headarray objectAtIndex:indexPath.row]; 
      cell.textLabel.text = [infoarray objectAtIndex:0]; 
     } 
    } 
} 
    else if(indexPath.section == 1){ 


    if(indexPath.row == 0){ 
//some more cell data 
} 

我認爲這應該是足以顯示我的問題!對細胞的產生

+0

你的問題是bit diffuse ..提供一些代碼並解釋你想要做什麼樣的檢查? – Stas 2012-02-09 17:18:01

+0

具體來說,如果您可以向我們展示您的'cellForRowAtIndexPath:'我們應該能夠弄清楚。 – yuji 2012-02-09 17:47:52

回答

0

粘貼代碼,看來你是不正確地使用複用小區機制

編輯: 代碼是不完整的,我認爲你應該做這樣的事情:

- (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]; 
    } 
    if(indexPath.section == 0){ 
     pinSwitch.hidden = YES; 
    cell.imageView.image = [UIImage imageNamed:@"test_item.png"]; 
    if([headarray count] != 0){ 
     if(indexPath.row > [headarray count] - 1){ 
      cell.imageView.alpha = 0; 
      cell.textLabel.text = [NSString stringWithFormat:@"Add new",indexPath.row + 1]; 

     } 
     else{ 
      cell.imageView.alpha = 1; 
      NSArray *infoarray = [headarray objectAtIndex:indexPath.row]; 
      cell.textLabel.text = [infoarray objectAtIndex:0]; 
     } 
    } 
} 
    else if(indexPath.section == 1){ 
     if(indexPath.row == 0){ 
    // you should fill cell data for all cases !!!! 
    } 
} else { // for example 
      cell.imageView.alpha = 1; 
      NSArray *infoarray = [headarray objectAtIndex:indexPath.row]; 
      cell.textLabel.text = [infoarray objectAtIndex:0]; 
} 
+0

我加了一些代碼 – kjeldGr 2012-02-09 22:06:56

+0

是的,我做到了!很抱歉對於這個誤會!我填滿了所有單元格數據!但如果第一部分不可見,則第二部分的單元格將獲得第一部分的一些單元格數據 – kjeldGr 2012-02-09 22:47:43

相關問題