MartinW
MartinW

Reputation: 248

Accessing UIButton in UITableViewCell

UIButton within a UITableViewCell is set to selected. When checking the button property on didSelectRowAtIndexPath shows as false.

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)

    var cell:UserActionsTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("userActionsCell") as! UserActionsTableViewCell

    if (cell.followButton.selected){
        //selected
    }
    else{
        // not selected
    }

How do I need to access the selected property?

Upvotes: 0

Views: 57

Answers (1)

Dharmesh Dhorajiya
Dharmesh Dhorajiya

Reputation: 3984

Don't use dequeueReusableCellWithIdentifier method in table didSelectRowAtIndexPath delegate method.

try this code :

let cell = tableView.cellForRowAtIndexPath(indexPath) as! UserActionsTableViewCell // get selected cell and use cell subView contains..
if (cell.followButton.selected){
    //selected
}
else{
    // not selected
}

Upvotes: 1

Related Questions