1

I want to set a UITableViewCell disclosure button but it doesn't work. I am using:

cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator 

In this function:

func tableView ( tableView : UITableView, cellForRowAtIndexPath indexPath: NsIndwxPath )-->UITableViewCell 
scott_lotus
  • 3,171
  • 22
  • 51
  • 69
user140963
  • 13
  • 2

3 Answers3

0

you can try this

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

or

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var CellIdentifier: String = "Cell"
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier)
if cell == nil {
    cell = UITableViewCell(frame: CGRectZero, reuseIdentifier: CellIdentifier)
}
cell.accessoryType = .DetailDisclosureButton
return cell
}

or you can do it using storyboard select your tableview cell from Document outline and go to attribute inspector and select disclourse indicator for your cell as shown in the picture

enter image description here

Umair Afzal
  • 4,947
  • 5
  • 25
  • 50
0

Try this

cell.accessoryType = .DetailDisclosureButton


func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {

        }
Sumeet Bajaj
  • 224
  • 2
  • 11
0

If you want a button on the side, use:

cell.accessoryType = .DetailButton

When it is tapped, do something in this method:

func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
    <#code#>
}
Pranav Wadhwa
  • 7,666
  • 6
  • 39
  • 61
  • how can I set a string to the `.DetailButton` that is shown in each cell? I mean, I can construct a cell using the indexPath of `accessoryButtonTappedForRowWithIndexPath` method and then once I have the cell, how can I set a String value to the cell's DetailButton ? `let cell = tableView.cellForRow(at: indexPath)` `cell?.accessoryView.text // no text property available on accessoryView` – bibscy Apr 03 '18 at 17:43
  • I believe you have to create a custom accessoryView to do so. Check out this question: https://stackoverflow.com/questions/35400214/how-to-add-label-text-to-detaildisclosurebutton – Pranav Wadhwa Apr 03 '18 at 20:55
  • I thought that there was an accessory view provided by default which would adjust itself on the screen same as a UILabel. Thanks – bibscy Apr 04 '18 at 10:40