Uitableview uitableview is used extensively in iOS, we organize the knowledge in UITableView uitableview is the table View controller 1 UITableView Initialize 2uitableview Implementation of proxy 3uitableview methods (Uitableviewdatasource) 3.1 How many cell are there in a group? 3.2 UITableViewCell Content 4 UIcollectionView Uicollectionview is the initialization of a collection view 1 uicollectionflowlayout 2 UIcollectionView 3 Uicollectionview Implement proxy 4 two methods that must be implemented //about UITableViewCell and Uicollectionviewcell Introduction uitableview comprehensive analysis in iOS development UITableView can be said to be the most widely used control, we usually use the software everywhere can see its shadow, Similar to, QQ, Sina Weibo and so on software basically everywhere is uitableview. Of course, its wide use is naturally inseparable from its powerful features, today this article will focus on the uitableview of discussion. Today's main content includes: UITableView has two kinds of styles: Uitableviewstyleplain and uitableviewstylegrouped. There is no essential difference between the two, except that the latter is shown in the Normal style by the grouping style. Let's take a look at the application of both 1> grouping styles 2> styles you can see that the data in UITableView is only the concept of rows, and there is no concept of columns, Because displaying multiple columns in the mobile operating system is not conducive to operation. Each row of data in the UITableView is a uitableviewcell in this control in order to show moreInformation, iOS has set up multiple child controls within it for developers to use. If we look at the UITableViewCell declaration file, we can find that there is an internal UIView control (Contentview, as the parent control of other elements), two uilable controls (Textlabel, Detailtextlabel), A UIImage control (imageView) for containers, display content, details, and pictures, respectively. Use effect similar to, QQ Information list: Of course, these sub-controls do not have to use all, the specific operation can be set through Uitableviewcellstyle, the specific meaning of each enumeration is commented in the Code: TypeDef ns_enum ( Nsinteger, Uitableviewcellstyle) { Uitableviewcellstyledefault,//left display Textlabel ( Do not display Detailtextlabel), ImageView selectable (shown on the leftmost) UITableViewCellStyleValue1,//Textlabel on the left, The right side shows Detailtextlabel (default blue), ImageView (shown on the leftmost) UITableViewCellStyleValue2,//left in turn textlable (default blue ) and Detailtextlabel,imageview selectable (shown on leftmost) Uitableviewcellstylesubtitle//upper left display Textlabel, The lower left shows Detailtextlabel (the default gray), ImageView Optional (shown on the leftmost)}; data source Since iOS is designed to follow the MVC pattern, many operations are communicated through agents and the outside world. But for the data source control in addition to the agent also has a data source property, through it and the outside world to interact with the data, for UITableView after setting up Datesource need to implement Uitableviewdatasource protocol, in this Protocol defines a variety of data operation methods, Below by creating a simple contact management for the demo run can see the following effect everyone in the use of the iphone communication will find the right can be retrieved alphabetically, easy to use, in fact, this feature uses UITableView realNow very simple, as long as the implementation of a data source protocol, the construction of a group header array can be implemented, the contents of the array element and the group header content may not be exactly the same, UITableView is based on the index of the array elements and each set of data index order to locate the results are not based on content Note that the order of execution of the above-mentioned key methods, see It is worth pointing out that the method of generating the cell is not called all at once, but only produces the cell currently displayed on the interface, and when the user scrolls, the other cells are displayed Note: As our application becomes more complex, it may often be necessary to debug the program, and in iOS you cannot navigate to the error line by default, and we can navigate to the error code line by setting the following: Show the breakpoint navigator-addexception breakpoint agent above we have seen the simple implementation of the Address book, but we found that the height of the cell, the height of the group headers and the height of the tail instructions need to be adjusted, you need to use the proxy method. There are many Uitalbleview proxy methods, such as monitoring cell display period, listening cell selection edit operation, setting whether to highlight cell, setting row High Level 1 setting Height 2 listening click on a contact in iOS to call this contact. Then we need to listen to the click Operation, here does not show the call contact operation, we demonstrate the operation of modifying the personnel information in the above code we modify the model to change the UI display, this is a classic MVC application, in the following code will often. Of course the UI refresh uses the UITableView Reloaddata method, which re-invokes the data source method, including calculating the grouping, calculating the number of rows per group, generating cells, and refreshing the entire uitableview. Of course this way in the actual development is not desirable, we can not modify a person's information to refresh the UITableView, at this time we need to adopt local refresh, local refresh is very simple to use, only need to call UITableView another method: Performance optimization It has been said that cell cell in UITableView is created after it is displayed to the user, but if the user scrolls down, it continues to create cells that are displayed on the screen, and if the user scrolls back to the viewed content, the previously created cells will be recreated as well. This way, even if the content of UITableView is not too much. If the user scrolls up and down repeatedly, the memory will soar instantly, not to mention that many times the content of the Uitalbleview is a lot (such as a microblog display list, basic downThere is no bottom limit for scrolling) We mentioned in the previous section how to optimize Uiscrollview, which was to use limited Uiimageview to dynamically switch its content to minimize resource usage. Similarly, a similar approach can be used in UITableView, but instead of scrolling to the specified position and changing the position of the scroll, the cell that is not currently displayed is re-displayed in the location of the cell that will be displayed and then its contents are updated. The reason is that the cell structure layout in UITableView may be different, and it is undesirable to reposition it, but to reuse a cell that has already been created that is not already displayed on the interface. Of course, it sounds complicated, but it's easy to implement because UITableView has already implemented this mechanism for us. There is a cache pool inside UITableView, initialized with Initwithstyle: (Uitableviewcellstyle) Reuseidentifier: (nsstring*) method to specify a reusable identity, You can put this cell in the cache pool. Then use the specified identity to go to the cache pool when using the corresponding cell and then modify the cell content uiscrollview uiscrollview is a sliding view uiscrollview initialization (if not initialized from Xib or storyboard) //properties contentsize // uiscrollview content size settings (this is very important) pagingenabled //Page Properties [_scrollview addsubview:imageview];//Add content view directly
Several Uitableview,uicollectionview uiscrollview key points