简体   繁体   English

UIPickerView选择链接到UITableView

[英]UIPickerView selection link to UITableView

How do I link a UIPicker view on one scene to a UITableViewController ? 如何将一个场景上的UIPicker视图链接到UITableViewController I have a picker view in one view controller populated with a number of categories, I want to segue to a table view controller when a category is selected/pressed. 我在一个填充了多个类别的视图控制器中有一个选择器视图,我想在选择/按下类别时选择一个表视图控制器。

First, create the segue in the Storyboard by Ctrl-dragging from the view controller to the new TableViewController (don't link from the picker, link from the view controller in which it appears). 首先,在Storyboard中通过按住Ctrl的方式从视图控制器中拖动到新的TableViewController (不要从选择器链接,也不要从出现它的视图控制器中的链接)中创建序列。 Select the segue and give it an appropriate identifier. 选择序列并为其提供适当的标识符。 In your UIPickerView delegate, implement the pickerView:didSelectRow:inComponent: method, and save the selected rows/components to properties. 在您的UIPickerView委托中,实现pickerView:didSelectRow:inComponent:方法,并将选定的行/组件保存到属性中。 Then invoke performSegueWithIdentifier:sender: to trigger the segue. 然后调用performSegueWithIdentifier:sender:来触发segue。

Separately, as part of the prepareForSegue method, read the properties you previously saved, and set the relevant properties of the segue destination view controller. 另外,作为prepareForSegue方法的一部分,读取以前保存的属性,并设置segue目标视图控制器的相关属性。

NB you may find, though, that this will trigger if the user hesitates whilst spinning through the picker view options. 注意,尽管如此,如果用户在选择器视图选项中旋转时犹豫不决,则会触发此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM