View refreshing method and device of application program, equipment and storage medium
By defining refresh protocols and refresh methods in the application, the problem of high code coupling and high business intrusion in the view refresh mechanism in the prior art is solved, and more efficient and flexible view refresh is achieved.
Patent Information
- Application Number
- CN202411486891.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-02-14
AI Technical Summary
In the prior art, the view refresh mechanism has problems such as high code coupling and high business intrusion, which leads to increased management complexity and increased development costs.
By predefining a refresh protocol and defining a refresh method in the protocol, the views and controllers that comply with the protocol can be flexibly refreshed, reducing intrusion into the original business.
It effectively reduces the degree of code coupling and business intrusion, improves the efficiency and flexibility of view refresh in applications, and is suitable for various business modules.
Smart Images

Figure CN119440575A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of application programs, and in particular to a method, apparatus, device and storage medium for refreshing a view of an application program. Background Art
[0002] In the development of modern highly complex applications (Application, APP), data refresh is a core function, which involves obtaining information from multiple data sources and reflecting this information in the user interface in real time.
[0003] Currently, existing view refresh technologies are usually implemented using a notification-based mechanism. When data changes, the system will issue a notification, and each view component will subscribe to these notifications as a listener (Observer) so as to refresh its own displayed content when receiving the notification.
[0004] However, the existing technology has technical problems such as high code coupling and high business intrusion. Summary of the invention
[0005] In view of the above problems, embodiments of the present invention provide a view refresh method, apparatus, device and storage medium for an application program, which are used to solve the technical problems of high code coupling and high business intrusion in the prior art.
[0006] According to one aspect of an embodiment of the present invention, a method for refreshing a view of an application is provided, the method comprising:
[0007] Get the target data that needs to be refreshed in the application;
[0008] According to the current controller of the application, determining a target view in a view corresponding to the current controller that complies with a preset refresh protocol; wherein a refresh method is defined in the refresh protocol, and an implementation of the refresh method is defined in the target view;
[0009] The refresh method in the target view is called to refresh the view according to the target data.
[0010] According to another aspect of an embodiment of the present invention, a view refreshing device for an application is provided, comprising:
[0011] The acquisition module is used to obtain the target data that needs to be refreshed in the application;
[0012] A determination module, configured to determine, according to a current controller of the application, a target view in a view corresponding to the current controller that complies with a preset refresh protocol; wherein a refresh method is defined in the refresh protocol, and an implementation of the refresh method is defined in the target view;
[0013] A refresh module is used to call the refresh method in the target view and refresh the view according to the target data.
[0014] According to another aspect of the embodiments of the present invention, there is provided an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0015] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the operation of the above-mentioned view refreshing method of the application program.
[0016] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, wherein at least one executable instruction is stored in the storage medium, and when the executable instruction is executed on a view refreshing device of an electronic device / application, the view refreshing device of the electronic device / application performs the following operations:
[0017] Get the target data that needs to be refreshed in the application;
[0018] According to the current controller of the application, determining a target view in a view corresponding to the current controller that complies with a preset refresh protocol; wherein a refresh method is defined in the refresh protocol, and an implementation of the refresh method is defined in the target view;
[0019] The implementation of the refresh method in the target view is called to refresh the view according to the target data.
[0020] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the computer program is used to implement the operation of the view refresh method of the above application program.
[0021] An embodiment of the present invention provides a view refresh method, device, equipment and storage medium for an application. In the method, by pre-defining a refresh protocol and defining a refresh method in the refresh protocol, the views and controllers that comply with the refresh protocol can be flexibly refreshed by means of the protocol, effectively reducing the intrusion into the original business. The method can be flexibly and conveniently applied to various business modules, thereby improving the efficiency of view refresh in the application.
[0022] The above description is only an overview of the technical solution of the embodiment of the present invention. In order to more clearly understand the technical means of the embodiment of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiment of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings are only used to illustrate the embodiments and are not to be considered as limiting the present invention. In addition, the same reference symbols are used to represent the same components throughout the accompanying drawings. In the accompanying drawings:
[0024] Figure 1 A flowchart showing a first embodiment of a method for refreshing a view of an application program provided by the present invention is shown;
[0025] Figure 2 A flow chart showing a second embodiment of the method for refreshing a view of an application program provided by the present invention;
[0026] Figure 3 A flowchart showing a third embodiment of the method for refreshing a view of an application program provided by the present invention is shown;
[0027] Figure 4 A flowchart of a fourth embodiment of the view refreshing method of an application provided by the present invention is shown;
[0028] Figure 5 A schematic diagram showing the structure of an embodiment of a view refreshing device for an application provided by the present invention;
[0029] Figure 6 A schematic structural diagram of an embodiment of an electronic device provided by the present invention is shown. DETAILED DESCRIPTION
[0030] Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein.
[0031] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and corresponding operation entrances shall be provided for users to choose to authorize or refuse.
[0032] First, the terms involved in the present invention are explained:
[0033] Protocol: An abstract specification that defines a set of rules, methods, and behaviors to guide the interaction and communication between different entities (such as classes, objects, components, or systems).
[0034] Methods: abstract operations or behaviors that specify the behavioral details that entities implementing the protocol must provide. Methods usually include a name, a parameter list, and a return type, which define how to perform a specific task or operation. Methods are defined in protocols as abstract interfaces that do not contain specific implementation code.
[0035] View: The visual part of the user interface, responsible for displaying data and responding to user interactions. Views usually contain UI elements such as buttons, labels, text boxes, images, etc., as well as layout and style information. The main responsibility of a view is to present data to the user in a visual form and provide an interface for the user to interact with the application. The view does not directly handle business logic, but passes user input events to the controller for processing.
[0036] Controller: The intermediary between the view and the model, responsible for processing user input, refreshing the model, and refreshing the view. The controller receives user interaction events from the view and refreshes the model or view based on these events. The controller contains the business logic and control logic of the application and decides how to respond to user operations. The controller is also responsible for reflecting data changes in the model to the view, or passing user input to the model for processing.
[0037] Singleton class: is a design pattern that ensures that a class has only one instance at any time and provides a global access point to access this instance. The singleton pattern is very useful in scenarios where you need to control resource sharing, configuration management, logging, etc., because it avoids repeated creation of objects, saves memory and improves performance.
[0038] Next, the scenarios involved in the present invention are explained in detail.
[0039] In modern highly complex application development, data refresh is a core function that involves obtaining information from multiple data sources and reflecting this information in real time on the user interface. These data sources may include but are not limited to remote servers, local databases, user input, sensor data, etc.
[0040] For example, in the in-vehicle infotainment system, the interior temperature, seat heating status, driving data, etc. need to be refreshed in real time through the vehicle interface so that the driver can view the latest data at any time.
[0041] Currently, existing view refresh technologies are usually implemented using a notification-based mechanism. Under this mechanism, when data changes, the system will issue a notification, and each view component will subscribe to these notifications as a listener so that it can refresh its own displayed content when receiving the notification.
[0042] However, the notification-based refresh mechanism has significant limitations in complex applications. As application functionality expands, the number of listening objects will increase dramatically, leading to increased complexity in managing these listening relationships. Each view component needs to correctly set and remove listeners during its life cycle, a process that is error-prone and difficult to maintain. Secondly, this model has a high degree of code intrusion on the original business module, that is, the business logic is tightly coupled with the data refresh logic, which is not conducive to code modularization and reuse. Finally, since each view component needs to handle the listening logic independently, this not only increases the development labor cost, but also reduces the overall performance and maintainability of the system.
[0043] In summary, the existing technology has the technical problems of high code coupling and high business intrusion. Therefore, a more efficient and controllable view refresh method is needed to meet the needs of modern applications for large-scale, secure, reliable and flexible data refresh.
[0044] Based on the above technical problems, the technical concept of the present invention is as follows: Considering that a blueprint is defined in the protocol, the methods, properties, and other necessary things used to implement a specific task or function are specified. Classes, structures, or enumerations can all follow the protocol and provide implementations for these requirements defined by the protocol. In addition, since view refresh is mainly to display the latest and most correct data to users, a preset refresh protocol can be predefined, and one or more refresh methods are defined in the preset refresh protocol. After obtaining the target data that needs to be refreshed in the application, the target view that follows the preset refresh protocol can be determined from the current controller, and the implementation of the refresh method in the target view can be executed to achieve the refresh of the target view. In this way, by means of the protocol, the views and controllers that comply with the protocol can be refreshed flexibly, which can effectively reduce the intrusion into the original business, and can be flexibly and conveniently applied to various business modules, thereby improving the efficiency of view refresh in the application.
[0045] The technical solution of the present invention is described in detail below through specific embodiments.
[0046] It should be noted that the following specific embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0047] Figure 1FIG. 1 is a flow chart showing a first embodiment of a method for refreshing a view of an application provided by the present invention, the method being executed by an electronic device. Figure 1 As shown, the method comprises the following steps:
[0048] Step 110: Obtain target data that needs to be refreshed in the application.
[0049] It should be understood that the execution subject of the embodiment of the present invention is an electronic device, which can be a terminal device, such as a laptop computer, a desktop computer, a vehicle-mounted terminal, etc., and can also be a server. In practical applications, whether the electronic device is a terminal device or a server can be determined according to actual conditions, and no specific limitation is imposed on this.
[0050] In a possible implementation manner, target data pushed by a software development kit (Software Development Kit, SDK) is obtained.
[0051] Exemplarily, the target data is data that needs to be displayed in the application. When the electronic device is a vehicle-mounted terminal and the application is running on the vehicle-mounted terminal, the target data can be at least one of the following:
[0052] Vehicle status data: including fuel level, battery charge, engine temperature, tire pressure, vehicle speed, mileage, etc.
[0053] Navigation and map data: real-time traffic information, road condition updates, navigation route changes, and more.
[0054] Entertainment system data: music playback status, radio frequency, playlist updates, audiobook chapter information, etc.
[0055] Climate control data: interior temperature, air conditioning settings, seat heating status, etc.
[0056] It should be understood that the target data may be one or more, which may be determined according to actual conditions, and the embodiment of the present invention does not impose any specific limitation on this.
[0057] Step 120: According to the current controller of the application, determine a target view that complies with a preset refresh protocol in a view corresponding to the current controller.
[0058] Among them, one or more refresh methods are defined in the refresh protocol, and the implementation of the refresh method is defined in the target view.
[0059] It should be understood that the implementation of the refresh method is the code used to implement the refresh method, which provides a way to implement the refresh method.
[0060] For example, suppose there is a refresh method a, whose function is to update the temperature value displayed in the air conditioning view. In order to realize this function, it is necessary to pre-write the code corresponding to the function, that is, the implementation body, and define the implementation body of the refresh method a in the air conditioning view.
[0061] It should be understood that the embodiment of the present invention does not limit the number of refresh methods defined by the refresh protocol, which can be determined according to actual conditions.
[0062] Optionally, the refresh protocol may be a Swift protocol.
[0063] The current controller is the controller in the application that the user is currently interacting with.
[0064] It should be understood that the controller may obtain data from the model and pass the data to one or more views. Therefore, the view corresponding to the current controller refers to the view that can transfer data with the current controller.
[0065] It should be understood that the number of target views may be one or more, which may be determined according to actual conditions, and the embodiment of the present invention does not specifically limit the number of target views.
[0066] In one possible implementation, you can first determine the current controller of the current view of the application, then traverse the views corresponding to the current controller, and determine whether each view complies with the preset refresh protocol through type checking, protocol compliance declarations, documents and annotations, and then determine the target view that complies with the preset refresh protocol from the views corresponding to the current controller.
[0067] In another possible implementation, a singleton class is implemented in the application, and the controller and the corresponding target view can be cached in the singleton class, so that the target view corresponding to the current controller can be obtained from the singleton class.
[0068] It should be understood that the implementation principle and process of this method will be Figure 2 The detailed description is given in the embodiment shown and will not be repeated here.
[0069] Step 130: Call the refresh method in the target view to refresh the view according to the target data.
[0070] In a possible implementation, a refresh method in the target view is called to pass the target data into the implementation body of the refresh method. Thereafter, the implementation body of the refresh method is run to display the target data in the target view to update the target view.
[0071] Specifically, since the implementation of the refresh method is defined in the target view, when you want to update the target view, you need to call the refresh method, obtain the corresponding target data, and inject the target data into the implementation of the refresh method. After that, you can call the implementation injected with the target data and display the target data in the target view to achieve the purpose of updating the target view.
[0072] Optionally, the target data can be updated in the target view according to the display mode corresponding to the target data. Exemplarily, assuming that the target data is implemented in the form of numerical values, the target data can be directly displayed in the target view; assuming that the target data is in the form of a chart, the chart is updated according to the target data (for example, the height of the bar chart is updated); assuming that the target data is displayed in the form of an image, it is necessary to update the target image corresponding to the target data. For example, the target data can be the weather type (sunny, rainy, snowy, etc.), and the display of the weather in the weather view is implemented in the form of an image. Then, after injecting the target data, the implementation body of the refresh method corresponding to the weather type can determine the weather type image corresponding to the target data and display it at the specified position of the target view.
[0073] In a specific scenario, if there are multiple target views, the refresh method in each target view needs to be called. Since the implementation of each refresh method defines the source of data, only the target refresh method corresponding to the target data will obtain the target data and refresh the target view defined with the target refresh method based on the target data.
[0074] For example, assume that the target view is the air conditioning view, the seat view, and the volume view, and the target data is the air conditioning temperature adjusted by the user. Then for the air conditioning view, the seat view, and the volume view, the latest data is obtained according to the refresh method deployed by themselves, that is, the latest air conditioning data (including the air conditioning temperature adjusted by the user), the latest seat data, and the latest volume data are obtained, and the air conditioning view, the seat view, and the volume view are refreshed according to the latest air conditioning data, the latest seat data, and the latest volume data. At this time, the air conditioning view will update and display the air conditioning temperature (target data) adjusted by the user, and the seat view and the volume view will not change before and after the refresh because the latest data obtained is consistent with their own data.
[0075] For example, assume that the target views are the seat view and the volume view, and the target data is the fuel level. Then for the seat view and the volume view, the latest data is obtained according to the refresh methods deployed by themselves, that is, the latest seat data and the latest volume data are obtained, and the seat view and the volume view are refreshed according to the latest seat data and the latest volume data obtained. Since the refresh methods deployed for the seat view and the volume view cannot match the fuel level, the target data cannot be refreshed to the seat view or the volume view. In other words, if the controller corresponding to the fuel level view is not the current controller, even if the current fuel level changes, the fuel level view will not be refreshed according to the current fuel level.
[0076] The view refresh method of the application provided in the embodiment of the present invention obtains the target data that needs to be refreshed in the application, and then determines the target view that follows the preset refresh protocol in the view corresponding to the current controller according to the current controller of the application. Finally, the refresh method in the target view is called to refresh the view according to the target data. Among them, the refresh method is defined in the refresh protocol, and the implementation of the refresh method is defined in the target view. In the embodiment of the present invention, by pre-defining a refresh protocol and defining a refresh method in the refresh protocol, the views and controllers that comply with the refresh protocol can be flexibly refreshed by means of the protocol, which effectively reduces the intrusion into the original business and reduces the code coupling with the original business. It can be flexibly and conveniently applied to various business modules, and improves the efficiency of view refresh in the application.
[0077] Figure 2 FIG. 1 is a flow chart showing a second embodiment of a method for refreshing a view of an application program provided by the present invention, wherein the method is executed by an electronic device. Figure 2 As shown, step 120 includes the following steps:
[0078] Step 210: Determine the current controller of the application.
[0079] In a possible implementation, the root view controller of the application is obtained, and then the current controller of the application is determined according to the root view controller.
[0080] Specifically, you can get the current rootViewController (root view controller) through UIApplication (singleton class), traverse the hierarchy of root view controllers, and determine the top controller as the current controller.
[0081] Step 220: Determine whether the target view corresponding to the current controller is cached in the singleton class.
[0082] In this implementation, the target view corresponding to each controller can be stored in the singleton class in the form of a dictionary. In the dictionary, the key is the controller, and the value is the view array corresponding to the controller, which includes multiple target views corresponding to the controller.
[0083] Among them, the singleton class can only store the target view corresponding to the current controller, and can also store the target views corresponding to other controllers. It can be determined according to the actual situation and will not be repeated here.
[0084] Optionally, determining whether the target view corresponding to the current controller is cached in the singleton class can be achieved in the following two ways:
[0085] Method 1: traverse the keys in the dictionary cached by the singleton class to determine whether the current controller exists. If so, it is determined that the target view corresponding to the current controller is cached in the singleton class. If not, it is determined that the target view corresponding to the current controller is not cached in the singleton class.
[0086] Method 2: To avoid storing too much redundant data in the singleton class, you can set the singleton class to store only the target view corresponding to the current controller. In this scenario, you can get the history controller stored by the root view controller at the previous moment. If the history controller is different from the current controller, it is determined that the target view corresponding to the current controller is not cached in the singleton class. If the history controller is the same as the current controller, it is determined that the target view corresponding to the current controller is cached in the singleton class.
[0087] Among them, if the historical controller is different from the current controller, the currently cached view in the singleton class also needs to be deleted.
[0088] In method 2, when the historical controller is different from the current controller, it means that the user has switched pages. At this time, only the target view corresponding to the historical controller is cached in the singleton class. Therefore, it is necessary to delete the target view corresponding to the historical controller cached in the singleton class and re-cache the target view corresponding to the current controller. Method 2 can effectively avoid caching too much redundant data in the singleton class, and by comparing the historical controller at the previous moment with the current controller, it can be determined whether the target view corresponding to the current controller is cached in the singleton class, which reduces the time spent on traversing the dictionary and improves data processing efficiency.
[0089] Step 230: If the target view corresponding to the current controller is cached in the singleton class, the target view is obtained from the singleton class.
[0090] In a possible implementation, a key-value pair whose key is the current controller is determined from a dictionary cached by the singleton class, and the value in the key-value pair is determined as the target view.
[0091] Step 240: If the target view corresponding to the current controller is not cached in the singleton class, recursively traverse the view corresponding to the current controller to obtain the target view.
[0092] Step 250: Associate the target view with the current controller and cache it into a singleton class.
[0093] In one possible implementation, the current controller can be used as the key and the target view as the corresponding value to generate a key-value pair, and the key-value pair can be cached in a singleton class.
[0094] The view refresh method of an application provided in an embodiment of the present invention determines the current controller of the application and determines whether the target view corresponding to the current controller is cached in the singleton class. If the target view corresponding to the current controller is cached in the singleton class, the target view is obtained from the singleton class. If the target view corresponding to the current controller is not cached in the singleton class, the view corresponding to the current controller is recursively traversed to obtain the target view, and the target view is associated with the current controller and cached in the singleton class. In an embodiment of the present invention, the target view corresponding to the controller can be cached by the singleton class. When the target view corresponding to the current controller needs to be refreshed, the time spent on traversing the view is reduced, thereby improving the refresh efficiency.
[0095] Based on any of the above embodiments, several specific examples are used to explain them.
[0096] Figure 3 FIG. 4 is a flow chart showing a third embodiment of a method for refreshing a view of an application program provided by the present invention, the method being executed by an electronic device. Figure 3 As shown, the view refresh method of the application may include the following steps:
[0097] Step 310: Get the root view controller.
[0098] Step 320: Determine whether the target view corresponding to the current controller is cached in the singleton class.
[0099] If the target view corresponding to the current controller is cached in the singleton class, step 330 is executed. If the target view corresponding to the current controller is not cached in the singleton class, step 340 is executed.
[0100] Step 330: recursively traverse the views corresponding to the current controller through the root view controller, determine the target view, associate the target view with the current controller, and cache it in a singleton.
[0101] Step 340: Get the target view.
[0102] When multiple target views are obtained, the multiple target views are traversed, and the refresh method in the target view is called through the generic object.
[0103] Step 350: Refresh the view.
[0104] Among them, the page view can be refreshed in the timed callback method.
[0105] Figure 4 FIG. 4 is a flowchart of a fourth embodiment of a method for refreshing a view of an application program provided by the present invention, the method being executed by an electronic device. Figure 4 As shown, the view refresh method of the application may include the following steps:
[0106] Step 410: Obtain target data pushed periodically by the SDK.
[0107] Step 420: Get the root view controller.
[0108] Step 430: Determine whether there is any change in the top controller.
[0109] That is, determine whether the history controller stored by the root view controller at the previous moment is the same as the current controller.
[0110] If the top controller has changed, then step 440 is executed. If the top controller has not changed, then step 460 is executed.
[0111] Step 440: recursively traverse the views corresponding to the current controller through the root view controller to determine the target view.
[0112] Step 450: associate the target view with the current controller and cache it in a singleton.
[0113] Step 460: traverse the obtained multiple target views and call the refresh method in the target view.
[0114] Step 470: Refresh the view.
[0115] Figure 5 FIG. 1 is a schematic diagram showing a structure of an embodiment of a view refreshing device for an application program provided by the present invention. Figure 5 As shown, the view refreshing device 500 of the application includes: an acquisition module 510 , a determination module 520 and a refreshing module 530 .
[0116] The acquisition module 510 is used to acquire target data that needs to be refreshed in the application.
[0117] The determination module 520 is used to determine, according to the current controller of the application, a target view in the view corresponding to the current controller that complies with a preset refresh protocol, wherein a refresh method is defined in the refresh protocol, and an implementation of the refresh method is defined in the target view.
[0118] The refresh module 530 is used to call the refresh method in the target view and refresh the view according to the target data.
[0119] In an optional manner, the determination module 520 is specifically configured to:
[0120] Determines the current controller for the application.
[0121] Determines whether the target view corresponding to the current controller is cached in the singleton class.
[0122] If the target view corresponding to the current controller is cached in the singleton class, the target view is obtained from the singleton class.
[0123] In an optional manner, the refresh module 530 is specifically configured to:
[0124] Call the refresh method in the target view and pass the target data into the implementation body of the refresh method;
[0125] Run the implementation body of the refresh method to display the target data in the target view to update the target view.
[0126] In an optional manner, the view refreshing device 500 of the application further includes a cache module, which is used to:
[0127] If the target view corresponding to the current controller is not cached in the singleton class, the view corresponding to the current controller is recursively traversed to obtain the target view.
[0128] Associate the target view with the current controller and cache it in a singleton class.
[0129] In an optional manner, the determination module 520 is specifically configured to:
[0130] Get the root view controller of the application.
[0131] Based on the root view controller, determine the current controller for the application.
[0132] In an optional manner, the determination module 520 is specifically configured to:
[0133] Get the history controller for the previous moment stored by the root view controller.
[0134] If the historical controller is different from the current controller, it is determined that the target view corresponding to the current controller is not cached in the singleton class.
[0135] If the historical controller is the same as the current controller, it is determined that the target view corresponding to the current controller is cached in the singleton class.
[0136] In an optional manner, if the historical controller is different from the current controller, the view refreshing device 500 of the application further includes a deletion module, which is used to:
[0137] Delete the currently cached view in the singleton class.
[0138] The application view refresh device realizes a unified, controllable and efficient application view refresh by pre-defining a refresh protocol and defining a refresh method in the refresh protocol. By utilizing the protocol characteristics, the views and controllers that comply with the refresh protocol can be refreshed flexibly, effectively reducing the intrusion on the original business. It can be flexibly and conveniently applied to various business modules, thereby improving the efficiency of view refresh in the application.
[0139] Figure 6 The schematic diagram of the structure of an embodiment of the electronic device provided by the present invention is shown, and the specific embodiment of the present invention does not limit the implementation of the electronic device.
[0140] like Figure 6 As shown, the electronic device may include: a processor (processor) 602 , a communication interface (Communications Interface) 604 , a memory (memory) 606 , and a communication bus 608 .
[0141] The processor 602, the communication interface 604, and the memory 606 communicate with each other via a communication bus 608. The communication interface 604 is used to communicate with other devices such as a client or other server network elements. The processor 602 is used to execute a program 610, which can specifically execute the relevant steps in the above-mentioned view refresh method embodiment for an application.
[0142] Specifically, the program 610 may include program code including computer executable instructions.
[0143] The processor 602 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiment of the present invention. The one or more processors included in the electronic device may be processors of the same type, such as one or more CPUs. They may also be processors of different types, such as one or more CPUs and one or more ASICs.
[0144] The memory 606 is used to store the program 610. The memory 606 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0145] The program 610 may be specifically called by the processor 602 to enable the electronic device to perform the following operations:
[0146] Get the target data that needs to be refreshed in the application.
[0147] According to the current controller of the application, a target view in the view corresponding to the current controller that complies with a preset refresh protocol is determined, wherein a refresh method is defined in the refresh protocol, and an implementation of the refresh method is defined in the target view.
[0148] Call the refresh method in the target view to refresh the view according to the target data.
[0149] In an optional manner, according to the current controller of the application, determining a target view that complies with a preset refresh protocol in a view corresponding to the current controller includes:
[0150] Determines the current controller for the application.
[0151] Determines whether the target view corresponding to the current controller is cached in the singleton class.
[0152] If the target view corresponding to the current controller is cached in the singleton class, the target view is obtained from the singleton class.
[0153] In an optional manner, a refresh method in a target view is called to refresh the view according to the target data, including:
[0154] Call the refresh method in the target view and pass the target data into the implementation body of the refresh method;
[0155] Run the implementation body of the refresh method to display the target data in the target view to update the target view.
[0156] In an optional manner, the program 610 is called by the processor 602 to enable the electronic device to perform the following operations:
[0157] If the target view corresponding to the current controller is not cached in the singleton class, the view corresponding to the current controller is recursively traversed to obtain the target view.
[0158] Associate the target view with the current controller and cache it in a singleton class.
[0159] In an optional manner, determining the current controller of the application includes:
[0160] Get the root view controller of the application.
[0161] Based on the root view controller, determine the current controller for the application.
[0162] In an optional manner, determining whether the target view corresponding to the current controller is cached in the singleton class includes:
[0163] Get the history controller for the previous moment stored by the root view controller.
[0164] If the historical controller is different from the current controller, it is determined that the target view corresponding to the current controller is not cached in the singleton class.
[0165] If the historical controller is the same as the current controller, it is determined that the target view corresponding to the current controller is cached in the singleton class.
[0166] In an optional manner, if the historical controller is different from the current controller, the program 610 is called by the processor 602 to enable the electronic device to perform the following operations:
[0167] Delete the currently cached view in the singleton class.
[0168] Electronic devices utilize protocol characteristics to allow views and controllers that comply with the refresh protocol to be refreshed flexibly, effectively reducing the intrusion into the original business. This can be flexibly and conveniently applied to various business modules, improving the efficiency of view refresh in the application.
[0169] An embodiment of the present invention provides a computer-readable storage medium, which stores at least one executable instruction. When the executable instruction runs on a view refresh device 500 of an electronic device / application, the view refresh device 500 of the electronic device / application executes the view refresh method of the application in any of the above-mentioned method embodiments.
[0170] The executable instructions may be specifically used to enable the view refreshing device 500 of the electronic device / application to perform the following operations:
[0171] Get the target data that needs to be refreshed in the application.
[0172] According to the current controller of the application, a target view in the view corresponding to the current controller that complies with a preset refresh protocol is determined, wherein a refresh method is defined in the refresh protocol, and an implementation of the refresh method is defined in the target view.
[0173] Call the refresh method in the target view to refresh the view according to the target data.
[0174] In an optional manner, according to the current controller of the application, determining a target view that complies with a preset refresh protocol in a view corresponding to the current controller includes:
[0175] Determines the current controller for the application.
[0176] Determines whether the target view corresponding to the current controller is cached in the singleton class.
[0177] If the target view corresponding to the current controller is cached in the singleton class, the target view is obtained from the singleton class.
[0178] In an optional manner, a refresh method in a target view is called to refresh the view according to the target data, including:
[0179] Call the refresh method in the target view and pass the target data into the implementation body of the refresh method;
[0180] Run the implementation body of the refresh method to display the target data in the target view to update the target view.
[0181] In an optional manner, the executable instructions enable the view refreshing device 500 of the electronic device / application to perform the following operations:
[0182] If the target view corresponding to the current controller is not cached in the singleton class, the view corresponding to the current controller is recursively traversed to obtain the target view.
[0183] Associate the target view with the current controller and cache it in a singleton class.
[0184] In an optional manner, determining the current controller of the application includes:
[0185] Get the root view controller of the application.
[0186] Based on the root view controller, determine the current controller for the application.
[0187] In an optional manner, determining whether the target view corresponding to the current controller is cached in the singleton class includes:
[0188] Get the history controller for the previous moment stored by the root view controller.
[0189] If the historical controller is different from the current controller, it is determined that the target view corresponding to the current controller is not cached in the singleton class.
[0190] If the historical controller is the same as the current controller, it is determined that the target view corresponding to the current controller is cached in the singleton class.
[0191] In an optional manner, the executable instructions enable the view refreshing device 500 of the electronic device / application to perform the following operations:
[0192] Delete the currently cached view in the singleton class.
[0193] Electronic devices utilize protocol characteristics to allow views and controllers that comply with the refresh protocol to be refreshed flexibly, effectively reducing the intrusion into the original business. This can be flexibly and conveniently applied to various business modules, improving the efficiency of view refresh in the application.
[0194] Optionally, an embodiment of the present invention further provides a computer program product, including a computer program, which is used to implement the operation of the view refresh method of the application shown in any of the above embodiments when the computer program is executed by a processor.
[0195] Computer-readable storage media utilizes protocol characteristics to allow views and controllers that comply with the refresh protocol to be refreshed flexibly, effectively reducing the intrusion into the original business. It can be flexibly and conveniently applied to various business modules, improving the efficiency of view refresh in the application.
[0196] The algorithms or displays provided herein are not inherently related to any particular computer, virtual system or other device. In addition, the embodiments of the present invention are not directed to any particular programming language.
[0197] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. Similarly, in order to simplify the present invention and help understand one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, the various features of the embodiments of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. Wherein, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, wherein each claim itself is a separate embodiment of the present invention.
[0198] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and further may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive.
[0199] The above embodiments illustrate the present invention rather than limit it, and those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be constructed as a limitation to the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The present invention may be implemented by means of hardware including several different elements and by means of appropriately programmed computers. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be understood as limitations on the order of execution.
Claims
1. A view refresh method for an application, characterized in that: The method comprises: Get the target data that needs to be refreshed in the application; According to the current controller of the application, determining a target view in a view corresponding to the current controller that complies with a preset refresh protocol; wherein a refresh method is defined in the refresh protocol, and an implementation of the refresh method is defined in the target view; The refresh method in the target view is called to refresh the view according to the target data.
2. The method according to claim 1, characterized in that The determining, according to the current controller of the application, a target view in the view corresponding to the current controller that complies with a preset refresh protocol includes: determining the current controller of the application; Determine whether the target view corresponding to the current controller is cached in the singleton class; If the target view corresponding to the current controller is cached in the singleton class, the target view is obtained from the singleton class.
3. The method according to claim 1 or 2, characterized in that: The calling the refresh method in the target view and refreshing the view according to the target data includes: Calling a refresh method in the target view, and passing the target data into an implementation body of the refresh method; The implementation body of the refresh method is run to display the target data in the target view to update the target view.
4. The method according to claim 2, characterized in that: The method further comprises: If the target view corresponding to the current controller is not cached in the singleton class, recursively traverse the view corresponding to the current controller to obtain the target view; The target view is associated with the current controller and cached in the singleton class.
5. The method according to claim 2 or 4, characterized in that: The determining the current controller of the application comprises: Get the root view controller of the application; The current controller of the application is determined based on the root view controller.
6. The method according to claim 5, characterized in that The determining whether the target view corresponding to the current controller is cached in the singleton class includes: Get the history controller of the previous moment stored by the root view controller; If the historical controller is different from the current controller, determining that the target view corresponding to the current controller is not cached in the singleton class; If the historical controller is the same as the current controller, it is determined that the target view corresponding to the current controller is cached in the singleton class.
7. The method according to claim 6, characterized in that If the historical controller is different from the current controller, the method further includes: Delete the currently cached view in the singleton class.
8. A view refreshing device for an application, characterized in that: The device comprises: The acquisition module is used to obtain the target data that needs to be refreshed in the application; A determination module, configured to determine, according to a current controller of the application, a target view in a view corresponding to the current controller that complies with a preset refresh protocol; wherein a refresh method is defined in the refresh protocol, and an implementation of the refresh method is defined in the target view; A refresh module is used to call the refresh method in the target view and refresh the view according to the target data.
9. An electronic device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the operation of the view refresh method of the application program as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The storage medium stores at least one executable instruction, and when the executable instruction is executed on the view refresh device of the electronic device / application, the view refresh device of the electronic device / application executes the operation of the view refresh method of the application as described in any one of claims 1-7.