UITableView部分,当上一部分超出iPhone屏幕时

时间:2012-02-09 17:10:38

标签: ios iphone xcode uitableview

我正在开发一个iPhone应用程序,并且在检查分组的tableview部分时遇到一些麻烦。当第一部分不再可见时,因为我向下滚动了桌面视图并且桌面视图反弹,第二部分从第一部分获取设置?我用indexPath.section值检查它是哪个部分。我怎么解决这个问题?对不起,如果我的英语不正确!

很抱歉找不到代码! 这是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
}

我认为这应该足以证明我的问题了!

1 个答案:

答案 0 :(得分: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];
}