[UIPickerView Case 07-Province and City Selection Interface Data Display 03-City Selection Bug Repair Objective-C Language]

1. Let’s first summarize the previous content - the province and city selection interface:

1. First, let’s talk about implementing a case. The first step is to look at the interface.

1) Step one: first look at the interface,

2) Step 2: Analyze its basic structure,

3) The third step: build the interface,

4) Step 4: Load data,

5) Step 5: Display data,

Is it five steps?

The big ones are just these five steps.

But this building interface,

Just one PickerView and two Labels,

Needless to say,

notify

no need,

This is very simple, we went through it directly,

2) Then, load the data,

need to say,

notify

No need, load it directly, an array,

This array contains some dictionaries,

Then, we want to convert it into a model,

So, some people say, dictionary, why should we convert it into a model?

Is it because of the order?

Let me tell you, this is not because of the order.

It's because when we write code, if you don't convert the model,

no problem either,

The order is still this. Whatever order is written here is the order.

notify

However, writing further down,

notify

When you retrieve these contents, how do you retrieve them?

Was it obtained through Key?

But what about this Key,

Are we @a string?

Sometimes, there are very few of us now, so we don’t make mistakes. But if there are ten or twenty, can we not guarantee that we will write it correctly every time?

So, we go to the dictionary to convert the model,

For such a reason,

In order to ensure that every time we write, we can directly "dot" and "dot",

It is very convenient and can ensure the correctness of what we write.

For this reason, we did this dictionary conversion model,

Then, load the data,

notify

Should we directly transfer this file in and write it directly into one sentence?

Then, load it into a dictionary array,

What's next, is it traversal and model transfer?

Then, during the process of converting the model,

Is it transferred through the class method? However,

This model, can you add it directly to this _provinces, inside,

Is our array an immutable array?

You can't add anything to it.

So, first use a temporary array,

Save the models you transferred out,

Then, after this traversal is completed, will this temporary array store all the dictionaries and transferred models in our plist file, right?

Then, we finally give this temporary array to our model array, and then return,

But here we said something,

_provinces = [arrM copy];

notify

Isn't this sometimes the case, and some people will write like this?

copy, immutable array, return,

//Copy an immutable array to the model array

notify

It’s okay to write it like this,

As long as you know, that's fine,

Because sometimes, others may write like this,

When we watch it, if we can understand it, then it’s OK.

Okay, this is where we load the data. We're done.

4) Next, is it necessary to display the data?

How to display data? In the first step, do you have to set its data source, proxy object,

Where did we set it up?

Is it directly in Main.storyboard? Then, right click,

Two attributes, drag them up,

notify

Is it the same for setting the data source, proxy object, and TableView before us?

Then, in the controller, do you have to abide by the corresponding protocol?

notify

That is our top, UIPickerViewDataSource, UIPickerViewDelegate

After complying with the agreement,

Whether to implement the data source method, proxy method,

In the data source method, these two methods

notify

What is it? It is @required and must be implemented.

1) numberOfComponentsInPickerView: But, how many groups are there?

Did we directly write it to death?

You can't return based on this array,

Our model array contains a bunch of models.

There are not that many groups at all,

So, you can just return directly,

2)numberOfRowsInComponent:component

Then, how many lines are there in each group?

This, I need to write for everyone: //How many rows are returned in each group?

notify

Do you need to write it like this? Just look at this: numberOfRowsInComponent,

numberOfRows: is the same as in TableView,

Then, here, we need to consider the situation.

notify

Because what is the difference between our province and city selection and our ordering system?

The two groups are related, right?

So, if you are in group 0,

How about it? How many rows are displayed? How many are there in your cities?

notify

You can display as many rows as there are provinces.

So, we can directly return the count of that model array.

2) Next, the city, this group,

How many cities are displayed?

notify

How do you know for sure?

Show how many cities you need to know first?

notify

What province do you show,

Only the cities in this province are what we want to display, right?

Would it be okay if I picked up its province?

Guess you like

Origin blog.csdn.net/madoca/article/details/132734530