Detailed requirements: In actual development, there may be a need for optimization in the later stage: the chat input box saves the previously entered text to improve the user experience. In the chat module, the user may enter a number of characters in the input box, but click to exit the chat without clicking Send, or click the user's avatar to confirm the user's information, or, for example, need to send another friend's ID to a friend and have to temporarily exit the current friend chat interface and jump to another interface to find the ID. However, the current chat input box has already entered a number of characters, and the user certainly does not want to delete the previously entered text after exiting. Therefore, it is necessary to temporarily save the string that the user has entered but not sent. However, it is also necessary to meet the following conditions: 1. To completely kill or exit the application, you need to clear the temporarily saved string; 2. After sending it out, you must delegate the previously temporarily saved string. start: At the beginning, I didn't have a good idea about how to implement this part of the logic. I only thought of local serialization, but in fact this is not the best idea, because local serialization is a bit of an overreaction here. In fact, just use the dictionary of global static variables. As for the specific implementation logic, I also specially read and studied the implementation of the Coding project. After all, this project is a relatively mature project, and the chat module is also very well done. So it is also good to learn from other people's ideas, as the saying goes, standing on the shoulders of giants. Next, I will directly interpret the logic of saving the content in the chat module in the Coding source code (Learning Coding-iOS Open Source Project Log (I)), instead of talking about the project I developed at work. 1. First, declare global static variables. In Coding, inputStrDict is used to store the string of the input box. I don’t know what inputMediaDict stores for the time being. It should be an element like media: 2. Then encapsulate a lot of logic in this UIMessageInputView class. No methods need to be made public. Just fully utilize the logic of the UIMessageInputView activity cycle.
The above is nothing more than concatenating the name of the chat object into a key value, then storing the string of the current input box into a global static dictionary, and then there are several methods for retrieving and deleting. 3. Let's see where these methods are called: The save method is placed in the method overridden by the frame, because the input box will switch frames as the keyboard is displayed and hidden. However, the chat module of my company's project was developed by my colleague at the beginning. I found that he used Masonry's layout code to change the position of the input box. Choosing layout constraints means giving up the frame, so where to call the save method should be based on actual needs and actual coding implementation. In addition, when developing this input box at the beginning, you can consider its operation cycle: start editing->editing->end editing. These operation cycles can implement their own methods, just like the life cycle of a controller. In short, there are many ideas, and doing a good job can implement logic that is easy to manage and maintain. Then find a way to delete it. The method of deletion is to put it at the very beginning of sending the string. Since it has been sent out, the elements stored in the dictionary can be deleted. In addition, when creating a key, the key string depends on the current chat object, because the content of the current input box must correspond to the current friend object one by one. I cannot save the content of the input box corresponding to the current friend, and then jump to another friend and see the same content. Therefore, the key value needs to be determined based on the string of the current friend, so the set method of the ToUser property is rewritten in the Coding source code: |
>>: Comparison of the latest shipments of Android and iPhone to see their system market share
Wang Zhongxuan liked to bray like a donkey. After...
Glass is one of the most fascinating materials in...
I believe that many friends who are new to SEO wi...
Volvo, which rarely has scandals, has recently be...
Unlike the quiet river valley, dense poplar fores...
Kunming tea tasting has its own studio. Recommend...
Source code introduction: Uber welcome page. Uber...
The fastest way to understand an industry is to m...
Do you sometimes wonder: Why does the battery of ...
E-commerce live streaming not only boosted consum...
Peter Drucker, the father of modern management, o...
What I want to share with you today is: In the cu...
During the past May Day holiday The most popular ...
Recently, Xiao Nei saw a piece of news that made ...
Unreal Engine UDK official video tutorial resourc...