2012-02-09 39 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

相关问题