Dereck
Dereck

Reputation: 95

How to setup Detail Accessory Type in Custom Cell

I have custom cell class for each cell I have on my table. I added detail accessory type to each cell. I want the user to click on the detail accessory type (the blue circle with i in it) and a pop up should show more information about that specific cell. I have googled around and have not found a solution for detail accessory type.

enter image description here

Following is the custom class for my first cell.

class SocialTableCell: UITableViewCell {

@IBOutlet weak var social:UILabel?  
@IBOutlet weak var toggle:UISwitch?

override func awakeFromNib() {
    super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
}
}

Any Help will be highly appreciated. Thanks

Upvotes: 0

Views: 767

Answers (1)

joern
joern

Reputation: 27620

The UITableViewDelegate protocol has a method tableView:accessoryButtonTappedForRowWithIndexPath: that is being called when a user tapped on the accessory button in one of the cells. So you have to implement that method in your TableViewController:

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
   // show the alert here
}

Also you have to make sure that you set the UITableView.delegate to the ViewController that implements that method.

Upvotes: 1

Related Questions