ios - 选择单元格时如何隐藏和显示 uiview UITableView

标签 ios objective-c uitableview uiview

基本上我想隐藏总是隐藏 uiview(带按钮),直到一个单元格被触摸然后它从单元格底部带动画(如果可能)调出 uiview

像这样:

enter image description here

我在一个应用程序中看到了这一点并爱上了它,并认为这将是很棒的用户体验。

请问我该如何存档,干杯

到目前为止的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *mycell=[tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];

    if (mycell==nil) {
        mycell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellIdentifier"];
    }
    UIView *myview = [[UIView alloc] initWithFrame:CGRectMake(0, 25, 320, 50)];
    [myview setBackgroundColor:[UIColor greenColor]];
    [mycell.contentView addSubview:myview];

    mycell.imageView.image = [UIImage imageNamed:@"placeholder.png"];
    mycell.textLabel.text = @"Song Title";
    UIFont *myFont = [ UIFont fontWithName: @"AppleSDGothicNeo-Bold" size: 12.0 ];
    [mycell.textLabel setTextColor: [UIColor colorWithRed:0.839 green:0.271 blue:0.255 alpha:1]];
    mycell.textLabel.font  = myFont;

    return mycell;
}

P.s myView 是我要添加的 View ,它将包含按钮。干杯!!!

最佳答案

此选项要求您的 UITableViewDelegateUITableViewDataSource 是同一个对象,这通常是这种情况。

  1. UITableViewDelegatetableView:didSelectRowAtIndexPath: 中,您可以管理一组选定的 indexPath 值,然后调用 [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]] 用于刚刚选择/取消选择的行。
  2. tableView:cellForRowAtIndexPath 中,您可以检查当前的 indexPath 是否在 UITableViewDelegate 方法管理的选定 indexPath 列表中,并采取适当的操作来显示/隐藏附加内容

关于ios - 选择单元格时如何隐藏和显示 uiview UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25072833/

相关文章:

ios - 选择一个单元格错误地将其他几个单元格标记为 "selected"

iphone - filterContentForSearchText 委托(delegate)方法中的 "scope"参数应包含什么?

ios - "Hide"ViewController 没有完全关闭它

ios - 在 UITableView 单元格中加载 UITableView 的最佳方法是什么?

c# - iOS 应用内购买(消耗品)- 服务器超时

ios - 使用 AFNetworking 从 S3 获取公共(public)文件并接收 403

ios - NSFetchedResultsController 只获取前 10 个项目

ios - 最优雅的旋转 UILabel 的方式;保持左下角

iphone - 清除应用程序的角标(Badge)编号

ios - UIAlertController 子类问题 swift