如何在按钮单击同一单元格内时隐藏/显示自定义tableview单元格内的特定视图 [英] how to hide/show a specific view inside the custom tableview cell when button click inside the same cell

查看:146
本文介绍了如何在按钮单击同一单元格内时隐藏/显示自定义tableview单元格内的特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我有一个表格视图 with(例如:20行)。并且我使用自定义表格视图单元格使用此表格视图

  • I have a table view with (ex : 20 rows). and I have used a custom table view cell with this table view.

在此表格视图单元格中,有少量标签,一个按钮隐藏视图(UIView)

inside this table view cell, there are few labels, one button and a hidden view (UIView).

I写了按钮 行动隐藏/显示 隐藏视图自定义表格视图单元格类 .it工作正常。但它会影响到其他在表格视图中。这意味着,当我点击第一行中的按钮,然后隐藏的视图显示,当向下滚动时,它可以在表视图的其他一些行中看到。

I have written button action for hide/show the hidden view inside the custom table view cell class.it works fine.but it affect to other rows in the table view. that means, when I tap the button in first row, then the hidden view show, and it can see in some other rows in the table view when scroll down.

同时(当隐藏/显示时),我想要增加减少行高(仅点击行/单元格)。出了什么问题。下面是我的代码和一些屏幕截图以获得一个想法。

At the same time (when hide/show), I want to increase and decrease the row height (only clicked row/cell) . what is going wrong. below is my codes and some screen shots to get an idea.

注意:当单击每个单元格中的展开按钮时,单元格会自动展开/增加。

这就是我隐藏 show 隐藏视图,位于自定义表格视图单元格类中。

this is how I hide and show the hidden view, inside the custom table view cell class.

- (IBAction)hideshow:(id)sender {
    BOOL ishidden = self.insideCollectionView.hidden;
    if(ishidden == true)
    {
        self.insideCollectionView.hidden = false;
    }
    else
    {
        self.insideCollectionView.hidden = true;
    }
}

出了什么问题,希望你对此有所帮助。

what is going wrong, hope your help with this.

高级:如果有一种方法可以在单击展开按钮时同时隐藏/显示和扩展(增加行高)对于每个单元格。

推荐答案

为我自己找到合适的解决方案。支持我的每个人。

Found the suited solution for this by my self. thanx everyone who supported me.

执行以下操作。


  1. 创建 NSMutableArray 中持有哪个 按钮哪个
    点击

  2. 然后当用户点击自定义表格视图单元格中的按钮时,请检查索引路径 已经在可变数组中,如果它是已经里面,然后 romove 它,否则加上它。

  3. 然后在 cellforrowatindexpath 方法,检查 nsmutable array 并检查 indexpath.row 存在

  4. 最后,如果它是存在,不要隐藏,否则隐藏它,这很有效。

  1. Create a NSMutableArray to hold Which button in Which row clicked.
  2. Then when user click on the Button in Custom table view cell, check it that index path is already in the mutable array, if it is already inside it, then romove it ,otherwise add it.
  3. Then in the cellforrowatindexpath method, check that nsmutable array and , check whether the indexpath.row is exist or not.
  4. Finally, if it is exists, do not hide, else hide it, this works perfectly.

这里是表视图的实现。 .m file

here is the implementation for the table view. .m file

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 25;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FirstTableViewCell *cells = [tableView dequeueReusableCellWithIdentifier:@"tvcell" forIndexPath:indexPath];

    NSString *theIndexpath = [NSString stringWithFormat:@"%ld", (long)indexPath.row];

//here check whether it is exists or not.
        if ([chekcme containsObject:theIndexpath])
        {
            cells.insideCollectionView.hidden = false;
        }
        else
        {
            cells.insideCollectionView.hidden = true;
        }



    [cells setColletionData:bbarray];

    [cells.expandMe addTarget:self action:@selector(runs:) forControlEvents:UIControlEventTouchUpInside];

//in here set the tag of the button to indexpath.row
    cells.expandMe.tag = indexPath.row;


    return cells;
}

//this is the action for the button inside the custom tableview cell.
- (IBAction)runs:(UIButton *)sender{

    NSString *myob = [NSString stringWithFormat:@"%li", (long)sender.tag];
    NSLog(@"%@",myob);

    if ([chekcme containsObject:myob]) {
        [chekcme removeObject:myob];
    }
    else
    {
        [chekcme addObject:myob];
    }


    NSLog(@"%@", chekcme);

//keep in mind to reload the table view here.
    [self.maintableView reloadData];
}




注意:checkme是NSMutableArray到保存用户点击的对象。

这篇关于如何在按钮单击同一单元格内时隐藏/显示自定义tableview单元格内的特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆