With the continuous iteration of the product and the continuous improvement of its functions, our project will present more and more things to users in different areas. Goodong’s selection gives users a concept of information plaza, so that users can quickly reach the point of interest. In this case, the general information page for each project is frequently changed. Location adjustments, new modules added, modules deleted, and so on. Then we must think about how we can build our part of the code so that we can accomplish the requirements of the product in the shortest time after the change. Maximize our work efficiency.

Below we through the goodong selection page to think about the specific implementation ideas





When we look at this picture, let’s ask ourselves a question: how many request interfaces are there in all these partitions? Some of you may say that this is not done by an interface? Then become a complicated json returned to the client, and then slowly to do, I want to this approach, the interface changes every time the server and the client is going to have a code, want to change a lot of things, this is at the ends of the developer must be not friendly, I also conveniently by Charles grasp the plump bag, my idea is verified, Their interface is really made up of multiple interfaces. So what are the benefits of having multiple interfaces?

Now, what if the product added a module in the next version, adjusted the order between the two modules, then deleted some modules, or even changed the order of multiple partitions? How can we make changes to minimize our code logic, reduce our workload?

Recently, we are reconstructing similar modules in our project. Now, the position of each partition in my TableView interface can be dynamically adjusted on the server side according to the operation data, and some modules can be dynamically deleted according to the operation data without changing the code of the client side. How is this done?

One of the things I do here is dynamic binding, WHERE I add a fixed identifier to the data for each partition as a whole and the server returns me a sort of data block, and I generate the data source for my TableView from those two points. The following is part of the implementation code. Recently, I will also write a small demo and put it on Github to share with you, so that we can efficiently complete our work together.

The first is the request code, of course, just pseudo code, I hope you mainly to understand a solution and ideas. Use dispatch_group to send multiple requests and refresh the interface when all requests are complete.





Each part can be regarded as a request. We will cache the request result of each module locally. If the data request fails in the next request, the last data will be read from the local. Then I’ll use pseudocode to write the basic form of the return that I’ve agreed with the server





Each request server tells me these three numbers in the data format it returns. These three data for my module sequence adjustment and dynamic deletion of the key. At this time, I first used adapter mode to add fixed attribute identifer to each returned book model. Since the number of requests was small, I used quicksort to convert the returned data into the data model and then created the data source of my TableView according to the two dimensions of sort and isUser.

We can dynamically deploy each cell according to the identifier and also set the height and other related content. This is the general idea. We will write a small demo recently, with the overall code.