[UIPickerView Case 02 - Order display data defaults to Objective-C language]
Mobile
2023-09-03 10:08:07
views: null
1. This display data![notify](https://img-blog.csdnimg.cn/556e963c5b7f4ce59eeabfba1813fe24.png#pic_center)
1. In it, there are data source protocol and proxy protocol. In the past, how to use it in TableView,
How did we do it before,
1) Step 1: Did you set the data,
![notify](https://img-blog.csdnimg.cn/a44904c601fe4135a17b42b0147b3194.png#pic_center)
Set the data source object, proxy object, and then,
Then, our Main.storyboard, right click,
![notify](https://img-blog.csdnimg.cn/822a9d84075445aa9f853b8918a3239b.png#pic_center)
Drag this data source object to the controller
![notify](https://img-blog.csdnimg.cn/7ac3ee05cb70477992c76ce6167f5971.png#pic_center)
The proxy object is also dragged into the controller
![notify](https://img-blog.csdnimg.cn/2d210a386d8c4fec8e3c7e4dc7e6ff86.png#pic_center)
Then, in the controller, do you abide by the corresponding protocol?
![notify](https://img-blog.csdnimg.cn/4365ab8e5b4e40ef8b2a82a7a15e4136.png#pic_center)
![notify](https://img-blog.csdnimg.cn/6915e9c44b514b3fb3d80afd233d69f7.png#pic_center)
![notify](https://img-blog.csdnimg.cn/f66ee01cd3c34d7aa3d85f5320e22ca4.png#pic_center)
![notify](https://img-blog.csdnimg.cn/2aab7807afe241f8a5444c855552de8c.png#pic_center)
Then, let’s go in and take a look, it’s the data source proxy protocol,
![notify](https://img-blog.csdnimg.cn/b7388dbfec4549919142053838a783da.png#pic_center)
Hold down the command key, jump in,
![notify](https://img-blog.csdnimg.cn/91efe6acf70a42dc97c3d26137bb639d.png#pic_center)
There are several data source methods,
only two,
1) numberOfComponentsInPickerView: returns how many groups you have
For this PickerView, its column by column is a group,
A column is a group,
2) numberOfRowsInComponent: how many rows per group,
Then, inside the PickerViewDelegate,
![notify](https://img-blog.csdnimg.cn/d8fe19ac272e448ab2d24c4cdfb1501f.png#pic_center)
Are these proxy methods,
![notify](https://img-blog.csdnimg.cn/2217ac3751d447959151c161bb0997ed.png#pic_center)
Then, do we want to display some text content now,
Let's see, which one do you need to use?
1) Is the return type NSString, and then,
titleForRow: What content is displayed in each row,
What headings are displayed on each line,
Now you know what to do, follow its protocol,
![notify](https://img-blog.csdnimg.cn/34e12ed34ca2451596857363afb99fdb.png#pic_center)
Delete this didReceiveMemoryWarning method
![notify](https://img-blog.csdnimg.cn/0e438af00d5a402fa41b72d374b580e6.png#pic_center)
Is there a way to achieve it, on the line,
what, is the first one
1)numberOfComponentsInPickerView:
![notify](https://img-blog.csdnimg.cn/28483cebfbf347fdabe347372752f3b9.png#pic_center)
returns how many groups there are, right,
2) Then, there is another one called, first enter a minus sign pickerView,
![notify](https://img-blog.csdnimg.cn/2b8c84e64c244a18a6cc27c56c4252ba.png#pic_center)
numberOfRowsInComponent:
![notify](https://img-blog.csdnimg.cn/010740dff16245e7ba97f7809733e71e.png#pic_center)
Return how many rows are in each group:
![notify](https://img-blog.csdnimg.cn/12ac504c672247d5b056207b9e28e107.png#pic_center)
But, have you noticed that in our PickerView, its display content is not in the proxy method,
![notify](https://img-blog.csdnimg.cn/df89d042ec6b407981ceee992c95eb96.png#pic_center)
Inside the TableView, where,
Return the content displayed by each row of Cell, whether it is in the data source method,
Here's a little difference between them,
Next, what to do,
![notify](https://img-blog.csdnimg.cn/48809052474b47debddf9ae8d150a807.png#pic_center)
1) numberOfComponents: whether to return how many groups,
How do you determine this group?
Have a look inside your array,
![notify](https://img-blog.csdnimg.cn/0f0edc0002364557ab1ebdb0a615c5a6.png#pic_center)
total?
Origin blog.csdn.net/madoca/article/details/132601451