问题
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.

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");
}
but it doesn't work!
Actually NSLog(@"you just select button");
works, but buttons never hides.
What should I do to get my buttons and hide them?
SOLVED:
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.
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)
{
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!
回答1:
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");
}
回答2:
cellForRowAtIndexPath
is called when Table get reloaded. In your case, what you have to do is:
- (void)button3Method:(id)sender
{
// Begin UITableView Update
[self.tableView beginUpdates];
NSIndexPath *indexPath = // Get cell indexpath for the selected row.
// Logic for getting the UITableViewCell on which you want hide two buttons.
// Logic for hiding those two buttons
// Below line performs reloading of particular UITableViewCell.
[self.tableView reloadRowsAtIndexPaths:@[indexPathOfYourCell] withRowAnimation:UITableViewRowAnimationNone];
// End UITaleView Update
[self.tableView endUpdates];
}
Let me know, if this works for you. Good luck.
回答3:
In cellForRowAtIndexPath:
[cell. settings addTarget:self action:@selector(selectSettings:) forControlEvents:UIControlEventTouchUpInside];
cell. settings.tag=600+indexPath.row;
In button IBAction:
-(void) selectSettings:(id) sender{
UIButton *btn=(UIButton *)sender;
cellMoreButtonIndex=btn.tag;
YOURCELL *cell=(YOURCELL *)[self.contentTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:btn.tag-600 inSection:0]];
[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);
}
}
回答4:
add a custom cell and Handle button click event and hide/unhide functionality on cell level
来源:https://stackoverflow.com/questions/27438220/hide-buttons-in-cell-by-other-button-press-uitableview