小编Mar*_*ews的帖子

iPhone - 使用自定义单元格展开UITableView并选择隐藏/显示标签

  • 我在UIView中有一个UITableView
  • 表视图的单元格是自定义的,因此由UITableViewCell类管理

我需要在选择时扩展/收缩单元格,我在这里使用了很棒的教程.但是,我还需要在选择时显示/隐藏UILabel - 就像详细视图一样,当您展开单元格时,会显示更多标签; 将其恢复到原始大小,并再次隐藏这些标签.

基本上:
单击"
延长单元格长度"
显示标签

再次单击
合同单元
隐藏标签

一次只打开一个单元格

这听起来很容易,但是在网络上普遍使用的方法(我上面链接的教程)会在第一次触摸时自动取消选择其单元格,这意味着我隐藏的UILabel永远不会有机会出现.

如果我删除

[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
Run Code Online (Sandbox Code Playgroud)

从didSelectRowAtIndexPath,我可以得到隐藏的标签,但它当然不会消失,因为在我选择不同的单元格之前,单元格不会被取消选择.

如何在单元用户第二次单击它后返回到常规高度时,单元格是否会自动取消选择?此外,有没有办法将表限制为一次只有一个扩展单元格,因为现在,您可以完全展开所有单元格.如果扩展Cell2会自动缩小Cell1回到原来的高度,我会喜欢它.

谢谢大家; 如果没有Stack Overflow,我不知道我会做什么.

TableViewController.h

@interface TableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
    IBOutlet UITableView *tableView;
    NSMutableDictionary *selectedIndexes;
}
@end
Run Code Online (Sandbox Code Playgroud)

TableViewController.m中的相关代码

@interface TableViewController (private)

- (BOOL)cellIsSelected:(NSIndexPath *)indexPath;

@end

@implementation TableViewController

#define kCellHeight 50.0

- (void)viewDidLoad {
    [super viewDidLoad];

    selectedIndexes = [[NSMutableDictionary alloc] init];
}


- (BOOL)cellIsSelected:(NSIndexPath *)indexPath {
    // Return whether the cell at the specified index path is …
Run Code Online (Sandbox Code Playgroud)

iphone height expand cell show-hide

3
推荐指数
1
解决办法
5340
查看次数

标签 统计

cell ×1

expand ×1

height ×1

iphone ×1

show-hide ×1