ios Swift-将披露指示器添加到 UITableViewCell
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27644537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift-Add disclosure indicator to a UITableViewCell
提问by Motoko
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.
我是 iOS 新手。我有 2 个表视图控制器,我希望用户单击 1 个单元格以导航到其他控制器。
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
但是,在这里您可以看到项目旁边的符号“>”,与 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.
但是我无法将导航项添加到单元格中,无论我使用什么 segue,“>”都不会显示。
Any idea?
任何的想法?
采纳答案by Abhishek Kumar
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'.
先说第一件事。如果需要在视图控制器之间进行导航,则需要将第一个视图控制器嵌入到导航控制器中。每个导航控制器维护一个堆栈,您可以在其中推送视图控制器。请参阅导航控制器文档。如果您希望默认显示“>”,请转到情节提要,单击单元格,转到右侧的第四个选项卡,选择附件作为“披露指示器”。
回答by Lyndsey Scott
That arrow isn't a UINavigationItem
; it's a UITableViewCellAccessoryDisclosureIndicator
.
那个箭头不是UINavigationItem
; 这是一个UITableViewCellAccessoryDisclosureIndicator
.
To add that UITableViewCellAccessoryDisclosureIndicator
"arrow" to your cell's accessory view, add this line:
要将UITableViewCellAccessoryDisclosureIndicator
“箭头”添加到单元格的附件视图中,请添加以下行:
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
And then to perform a specific action when that accessory view is tapped, implement tableView:accessoryButtonTappedForRowWithIndexPath:
.
然后要在点击该附件视图时执行特定操作,请实现tableView:accessoryButtonTappedForRowWithIndexPath:
.
回答by meaning-matters
In Swift 4 and Swift 5 this would be:
在 Swift 4 和 Swift 5 中,这将是:
cell.accessoryType = .disclosureIndicator
You can also set it in IB if appropriate: Attributes Inspector > Table View Cell > Accessory.
如果合适,您也可以在 IB 中设置它:属性检查器 > 表格视图单元格 > 附件。