通过按其他按钮隐藏单元格中的按钮

通过按其他按钮隐藏单元格中的按钮

本文介绍了通过按其他按钮隐藏单元格中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道如何在 UITableView 中获取每个单元格的所有项目。我的问题是,当选择第三个按钮时,我想在单元格中隐藏2个按钮。

Wondering how can I get all items of each cell in UITableView. My problem is that I want to hide 2 buttons in cell when third is selected.

当我按下按钮1时,按钮2和3必须隐藏。我为此尝试做的(在cellForRowAtIndexPath中):

When I press on button 1, button 2 and 3 must be hidden. What I tried to do for that (in cellForRowAtIndexPath) :

AVMMovieButton *settings = (AVMMovieButton *)[cell viewWithTag:228];
[settings addTarget:self action:@selector(selectSettings:) forControlEvents:UIControlEventTouchUpInside];
settings.tag = indexPath.row;

AVMMovieButton *playButton = (AVMMovieButton *)[cell viewWithTag:134];
[playButton setStore:oneItem];
[playButton addTarget:self action:@selector(playMovie:) forControlEvents:UIControlEventTouchUpInside];
playButton.tag = indexPath.row;

AVMMovieButton *down = (AVMMovieButton *)[cell viewWithTag:282];

AVMMovieButton *del = (AVMMovieButton *)[cell viewWithTag:161];

[settings  setSelected:!settings.isSelected];
if (settings.isSelected)
{
    NSLog(@"SELECTED!");

    down.hidden = YES;
    del.hidden = YES;
    downLabel.hidden = YES;
    delLabel.hidden = YES;

   // [self performSelector:@selector(playButtonShow) withObject:nil afterDelay:0.3];
    playButton.hidden = NO;
}
else
{
    NSLog(@"UNSELECTED!");

    playButton.hidden = YES;
    down.hidden = NO;
    del.hidden = NO;
    downLabel.hidden = NO;
    delLabel.hidden = NO;

    NSLog(@"play button %d",playButton.hidden);
}

然后我添加了选择设置按钮的方法:

and then I added method for selecting my "settings" button:

-(void)selectSettings:(AVMMovieButton *)sender
{
    [sender setSelected:!sender.isSelected];
    NSLog(@"you just select button");
}

但这不起作用!

实际上是 NSLog(@您只需选择按钮); 起作用,但按钮永远不会隐藏。

Actually NSLog(@"you just select button"); works, but buttons never hides.

我该怎么做才能隐藏按钮?

What should I do to get my buttons and hide them?

已解决:

我要做的就是创建自定义的 UITableViewCell 类,然后按照Jay Gajjar和Akhilrajtr的说明访问我的单元。在我刚刚使用方法选择/取消选择我的按钮之后。

All I needed to do was to create custom UITableViewCell class and then access my cell as Jay Gajjar and Akhilrajtr said. After I just used my method for select/deselect my button.

我所拥有的:

-(void)selectSettings:(AVMMovieButton *)sender
{
    AVMMovieButton *settings = (AVMMovieButton *)sender;
    CGPoint pointInTable = [settings convertPoint:settings.bounds.origin toView:readyTable];
    NSIndexPath *indexPath = [readyTable indexPathForRowAtPoint:pointInTable];
    AVMMovieCell *cell=(AVMMovieCell *)[readyTable cellForRowAtIndexPath:indexPath];
    if (cell.settingsButton.isSelected)
    {
        NSLog(@"SELECTED!");

        cell.downloadButton.hidden = YES;
        cell.deleteButton.hidden = YES;
        cell.downLabel.hidden = YES;
        cell.delLabel.hidden = YES;
        cell.playButton.hidden = NO;
    }
    else
    {
        NSLog(@"UNSELECTED!");
        cell.playButton.hidden = YES;
        cell.downloadButton.hidden = NO;
        cell.deleteButton.hidden = NO;
        cell.downLabel.hidden = NO;
        cell.delLabel.hidden = NO;
        NSLog(@"play button %d",cell.playButton.hidden);
    }
    [settings setSelected:!settings.isSelected];
}

希望这对其他人会有所帮助!

Hope this can be helpful for somebody else!

推荐答案

尝试一下,

-(void)selectSettings:(AVMMovieButton *)sender{

    [sender setSelected:!sender.isSelected];
    CGPoint pointInTable = [sender convertPoint:sender.bounds.origin toView:_tableView];
    NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:pointInTable];
    [_tableView beginUpdates];
    [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [_tableView endUpdates];
    NSLog(@"you just select button");
}

这篇关于通过按其他按钮隐藏单元格中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:15