Reputation: 1132
I'm new to iOS. I had 2 Table View Controllers and I want user to click on 1 cell to navigate to the other Controllers.
However here you can see the sign ">" next to the item, same as in Settings app in iOS 8. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewAndDataModel/TableViewAndDataModel.html
But I cannot add Navigation Item to a cell and no matter what segue I use the '>' doesn't show up.
Any idea?
Upvotes: 34
Views: 43839
Reputation: 37300
That arrow isn't a UINavigationItem
; it's a UITableViewCellAccessoryDisclosureIndicator
.
To add that UITableViewCell.AccessoryType.disclosureIndicator
"arrow" to your cell's accessory view, add this line:
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
And then to perform a specific action when that accessory view is tapped, implement tableView:accessoryButtonTappedForRowWithIndexPath:
.
Upvotes: 86
Reputation: 22946
In Swift 4 and Swift 5 this would be:
cell.accessoryType = .disclosureIndicator
You can also set it in IB if appropriate: Attributes Inspector > Table View Cell > Accessory.
Upvotes: 21
Reputation: 324
First things first. If you need navigation between view controllers, you need to embed the first view controller in a navigation controller. Each navigation controller maintains a stack on which you can push view controllers. Please refer to the navigation controller documentation. If you want the '>' show up by default, goto the storyboard, click on the cell, goto the fourth tab on the right hand side, select the accessory as 'Disclosure Indicator'.
Upvotes: 13