vendettacore vendettacore - 1 year ago 92
iOS Question

Hide buttons in cell by other button press uitableview

Wondering how can I get all items of each cell in

. My problem is that I want to hide 2 buttons in cell when third is selected.

example of my cell

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)

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

// [self performSelector:@selector(playButtonShow) withObject:nil afterDelay:0.3];
playButton.hidden = NO;

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");

but it doesn't work!

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

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


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

What I've got:

-(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)

cell.downloadButton.hidden = YES;
cell.deleteButton.hidden = YES;
cell.downLabel.hidden = YES;
cell.delLabel.hidden = YES;
cell.playButton.hidden = NO;
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!

Answer Source

Try this,

-(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");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download