iOSBeginner
iOSBeginner

Reputation: 1

Show hide button on a tableview cell,ios

I am trying to initially hide the button on a UITableViewCell and want to show that button when I click on the label on the same UITableViewCell. I tried setting isEnabled and userInteraction = YES/NO, but no luck. Please tell me any other method ??

Upvotes: 0

Views: 1224

Answers (3)

Gaurav Tiwari
Gaurav Tiwari

Reputation: 44

In your tableview cell's class, you can initially hide the cell's button as shown in the code below:

class SettingsTVC: UITableViewCell {

    @IBOutlet weak var lblLanguage: UILabel!
    @IBOutlet weak var btnArrow: UIButton!

    override func awakeFromNib() {
        super.awakeFromNib()
        btnArrow.isHidden = true
    }
}

Later in the select delegate of the tableview, you can get access to the button of that particular cell and unhide the button.

Let me know if further help is required.

Upvotes: 0

TheHungryCub
TheHungryCub

Reputation: 1960

Try to do it like following way, I hope it will help you:

1) Assign a tag to each button in if statement :

buttonFlag.tag = indexPath.row:

2) Find the button by its tag and set hidden in else statement :

else if ([[self.flags objectAtIndex:indexPath.row] isEqualToString:@"true"])
{
 UIButton *buttonFlag = [cell.contentView viewWithTag:indexPath.row];
 [buttonFlag setHidden:YES];
}

Upvotes: 0

norders
norders

Reputation: 1252

button.hidden = YES is the normal way to hide UIView-based elements.

Upvotes: 1

Related Questions