UItable Cell Overflow ios

Gih*_*han 6 objective-c uitableview custom-cell ios ios-4.2

我正在做一个需要扩展单元格的应用程序,以显示更多细节.我使用了自定义单元格并将它们添加到UItableview中.当我点击单元格时,它会动画很好并且向下移动,当我再次单击它时,它会上升,这是通过更改单元格的高度来完成的.实际的自定义单元格大小比我通常显示的单元格大.当我点击细胞时,显示整个细胞.我遇到的唯一问题是数据溢出.未选择单元格时,应隐藏这些数据.只有在选择时才应显示这些数据.

我提到了不同的文章,尝试改变颜色设置绑定对我不起作用.我有同样的问题在这个问题iphone uitablecellview溢出问,尝试了答案,但它没有奏效.

我需要的是如何在未扩展时隐藏自定义单元格的底部部分,并在扩展时显示它!...

这些是我的屏幕截图

当它被加载 当它被加载 当我点击一个单元格 当我点击一个单元格] 当我点击第二个单元格时 当我点击第二个单元格时 当我点击扩展的单元格时
当我点击已经展开的单元格时这些是我用过的代码剪辑....

// Declaring the SearchResultTable.
    CGRect filterFrame = CGRectMake(0,31, 320, 400);
    self.searchResultTable = [[UITableView alloc] initWithFrame:filterFrame];
    self.searchResultTable.dataSource = self;
    self.searchResultTable.delegate = self;
    self.searchResultTable.backgroundColor = [UIColor whiteColor];
    self.searchResultTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.searchResultTable.separatorColor = [UIColor lightGrayColor];
    [self.view addSubview:self.searchResultTable];

//Adding cells
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"ExpandedSearchResultTableCell";


    ExpandedSearchResultTableCell *cell = (ExpandedSearchResultTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil)
    {
        cell.contentView.clipsToBounds = YES;
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExpandedSearchResultTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];


    }

    cell.productNameLable.text = @"Only this should be shown";
    cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded";
    cell.productApplicationLable.text=@"This Should be hidden.. Only shown when expanded";
    cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded";
    cell.productQuantityLable.text=@"This Should be hidden.. Only shown when expanded";
    cell.productReactivityLable.text=@"This Should be hidden.. Only shown when expanded";;


    return cell;
}


//on click event
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {




    // Deselect cell
    [tableView deselectRowAtIndexPath:indexPath animated:TRUE];

    // Toggle 'selected' state
    BOOL isSelected = ![self cellIsSelected:indexPath];

    // Store cell 'selected' state keyed on indexPath
    NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
    [selectedIndexes setObject:selectedIndex forKey:indexPath]; 

    // This is where magic happens...
    [searchResultTable beginUpdates];
    [searchResultTable endUpdates];
}

//Getting the height depending on expanded or not
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    // If our cell is selected, return double height
    if([self cellIsSelected:indexPath]) {
        return kCellHeight * 3.0;
    }

    // Cell isn't selected so return single height
    return kCellHeight;
}
Run Code Online (Sandbox Code Playgroud)

Gih*_*han 1

好的,我通过在 didSelectRowAtIndexPath 中使用单个标志和对 cellForRowAtIndexPath 单元格的引用来完成此操作。并根据折叠和拉伸设置我的标签可见和隐藏。标志会根据单元格是否被选择而相应更新......!!

谢谢你帮助大家..!