Reputation: 15
I have a TableViewController
with my customed TableViewCell
, on each row there are two buttons, one is hidden the other is not, when I tap the shown button I want to show the other button, I´ve covered this, my problem is, if I scroll down other hidden buttons are showed because of the Reuseidentifier.
What can I do to only show up the button from the row I`ve selected.
Hope I got clear if not please ask me.
Thank you all.
Upvotes: 0
Views: 82
Reputation: 370
When you scroll the tableView remaining buttons are hidden because you wrote setHidden method in cellForRowAtIndexPath
Without putting any condition so take one NSMutableArray and allocate memory to it. Whatever the index you select just add it MutableArray.Then in cellForRowAtIndexPath
Put one condition if that array contains the indexPath don't hide else hide the button.
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CutomTableView *cell=[tableView dequeueReusableCellWithIdentifier:@"CellId" forIndexPath:indexPath];
[cell.show setTag:indexPath.row];
[cell.show addTarget:self action:@selector(showButtonACtion:) forControlEvents:UIControlEventTouchUpInside];
NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
//self.selectedRow is NSMutable Array
if ([self.selectedRow containsObject:selectedIndexPath]) {
[cell.hideBtn setHidden:NO];
}else{
[cell.hideBtn setHidden:YES];
}
return cell;
}
-(void)showButtonACtion:(UIButton*)sender{
NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
[self.selectedRow addObject:myIP];
[self.tableV reloadData];
}
Upvotes: 1
Reputation: 3833
-(IBAction)firstButton:(UIControl *)sender
{
UIButton *button = (UIButton*)sender;
NSIndexPath *myIP = [NSIndexPath indexPathForRow:sender.tag inSection:0];
CustomCell *cell = (CustomCell*)[self.tableView cellForRowAtIndexPath:myIP];
[cell.button2 setHidden:NO];.
}
Upvotes: 0
Reputation: 982
When you click on particular button to show another button, just save that NSIndexpath.
For example, If you are click on 2nd row, then add value in NSMutableDicionary as
[mutableDict setValue:@"YES" forKey:[NSString stringWithFormat:@"%@", indexPath.row]];
And then check for particular indexPath in cellForRowAtIndexPath method.
Whenever you find @"YES" for particular row, implement your desired logic to show or hide buttons.
Hope this helps you.
Upvotes: 0