An explanation of the use of TableView in the iOS development UI Chapter

Source: Internet
Author: User
<span id="Label3"></p><p><p>1. We know that TableView is a high-level view of ios, with its inheritance and scrollview, so we know he has all the features of SCROLLVIEW. And it has expanded a lot. Of course, This is not introduced Here.</p></p><p><p>The presentation format of the 2.tableView is divided into two types of plain and grouped two styles</p></p><p><p>The two proxy classes of the 3.tableView delegate and datasource. these two proxies are important, and we are inseparable in doing tableview and these Proxies.</p></p><p><p>4. Proxy methods that are more commonly used in proxies:</p></p><p><p>(1) two agents that must be used for DataSource</p></p><p class="p1"><p class="p1"><span class="s1">@required</span></p></p><p class="p1"><p class="p1"><span class="s1">Displays the number of cells in the UITableView</span></p></p><p class="p2"><p class="p2"><span class="s1">-(<span class="s2">Nsinteger<span class="s1">) tableView: (<span class="s2">uitableview<span class="s1"> *) tableView numberofrowsinsection: (<span class="s2">nsinteger<span class="s1">) Section </span></span></span></span></span></span></span></p></p><p class="p2"><p class="p2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1">The interaction of cell and model data</span></span></span></span></span></span></span></p></p><p class="p2"><p class="p2"><span class="s1">-(<span class="s2">UITableViewCell<span class="s1"> *) tableView: (<span class="s2">uitableview<span class="s1"> *) tableView cellforrowatindexpath: (<span class="s2">nsindexpath <span class="s1">*) indexpath</span> </span> </span> </span> </span> </span></span></p></p><p class="p2"><p class="p2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1">(2) Common agent method of delegate</span></span></span></span></span></span></span></p></p><p class="p2"><p class="p2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1">@</span></span></span></span></span></span></span> <span class="s1">Optional</span></p></p><p class="p2"><p class="p2"><span class="s1">Used to set the height of the TableView</span></p></p><p class="p1"><p class="p1"><span class="s1">-(<span class="s2">cgfloat<span class="s1">) tableView: (<span class="s2">uitableview<span class="s1"> *) tableView heightforrowatindexpath: (<span class="s2">nsindexpath<span class="s1"> *) Indexpath</span> </span> </span> </span> </span> </span></span></p></p><p class="p1"><p class="p1"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1">Method called when the cell is selected</span></span></span></span></span></span></span></p></p><p class="p1"><p class="p1"><span class="s1">-(<span class="s2">void<span class="s1">) tableView: (<span class="s3">uitableview<span class="s1"> *) tableView didselectrowatindexpath: (<span class="s3">nsindexpath<span class="s1"> *) Indexpath</span> </span> </span> </span> </span> </span></span></p></p><p class="p1"><p class="p1"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1">4. In general, these four agents have been able to handle the function TableView no problem, but sometimes when we do tableview, Tableview's first cell or the last cell and the other cell is different, so we may use the following two functions</span></span></span></span></span></span></span></p></p><p class="p1"><p class="p1">Data interaction for the cell and model of the TableView head</p></p><p class="p1"><p class="p1"><span class="s1">-(<span class="s2">UIView<span class="s1"> *) tableView: (<span class="s2">uitableview<span class="s1"> *) tableView viewforheaderinsection: (<span class="s2">nsinteger<span class="s1">) </span></span> </span> </span> </span> </span> section</span></p></p><p class="p1"><p class="p1"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1">Defines the height of the TableView head</span></span></span></span></span></span></span></p></p><p class="p1"><p class="p1"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1">-(<span class="s2">cgfloat<span class="s1">) tableView: (<span class="s2">uitableview<span class="s1"> *) tableView heightforheaderinsection: (<span class="s2">nsinteger<span class="s1">) </span></span> </span> </span> </span> </span> section</span></span></span></span></span></span></span></p></p><p class="p1"><p class="p1">Data interaction for the cell and model of the TableView tail</p></p><p class="p1"><p class="p1"><span class="s1">-(<span class="s2">UIView<span class="s1"> *) tableView: (<span class="s2">uitableview<span class="s1"> *) tableView viewforfooterinsection: (<span class="s2">nsinteger<span class="s1">) </span></span> </span> </span> </span> </span> section</span></p></p><p class="p1"><p class="p1"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1"><span class="s2"><span class="s1">Defines the height of the tail of the TableView</span></span></span></span></span></span></span></p></p><p class="p1"><p class="p1"><span class="s1">-(<span class="s2">cgfloat<span class="s1">) tableView: (<span class="s2">uitableview<span class="s1"> *) tableView heightforfooterinsection: (<span class="s2">nsinteger<span class="s1">) Section </span></span></span></span></span></span></span></p></p><p class="p1"><p class="p1">5. There is also a method that should be tableview for the object that comes with these two properties</p></p><p class="p1"><p class="p1">For example:</p></p><p class="p1"><p class="p1">The Ableview object comes with properties that have both properties to note that he receives the object <span class="s1">UIView<span class="s2"> </span> </span></p></p><p class="p1"><p class="p1"><span class="s1"><span class="s2">//</span></span></p></p><p class="p1"><p class="p1"><span class="s1"><span class="s2"></span></span></p></p><p class="p1"><p class="p1"><span class="s1">Self<span class="s2">. Tableview.tablefooterview</span></span></p></p><p class="p1"><p class="p1"><span class="s1">Self<span class="s2">. TableView.</span> Tableheaderview</span></p></p><p class="p1"><p class="p1">The above basically can make the complete tableview. well, Let's take a look at the TableView Extension.</p></p><p class="p1"><p class="p1">6. We know that tableview inherit from scrollview, but ScrollView sometimes load too much things when using large memory, will cause the cell phone card dead; at this time we generally have three ways to solve, one, reuse ScrollView two, using waterfall flow three, Using Transverse TableView</p></p><p class="p1"><p class="p1">Using Transverse tableview:</p></p><p class="p1"><p class="p1">The example is just a file that I took out of the project, which may not work, but it can be used to learn the steps</p></p><p class="p1"><p class="p1">There is no change in the agent function, but the center and frame are changed</p></p><p class="p1"><p class="p1">frame requires x and y width and length to be reversed</p></p><p class="p1"><p class="p1">There are several important codes in the transverse tableview</p></p><p class="p1"><p class="p1">These two words: the first sentence is the TableView horizontal rotation, The second sentence is to change the TableView center. These two sentences are placed in the Tabbleview object definition, the following "setup interface" code is visible</p></p><p><p>Table.transform = Cgaffinetransformmakerotation (-m_pi/2);<br>Table.center = cgpointmake (self.view.frame.size.width/2, SELF.VIEW.FRAME.SIZE.HEIGHT/2 + 30);</p></p><p><p>This sentence is placed in the cell and model data interaction, which is the role of the cell also rotated horizontally<br>Cell.contentView.transform = Cgaffinetransformmakerotation (m_pi/2);</p></p><pre><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Setup Interface</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) settingsview{self.tableviewx</span></span>= [[uitableview alloc] Initwithframe:cgrectmake (<span style="color: #800080;"><span style="color: #800080;"></span> -</span>,<span style="color: #800080;"><span style="color: #800080;">0</span></span>, HEIGHT-<span style="color: #800080;"><span style="color: #800080;"></span> -</span><span style="color: #000000;"><span style="color: #000000;">, WIDTH)]; Self.tableViewX.transform</span></span>= Cgaffinetransformmakerotation (-m_pi/<span style="color: #800080;"><span style="color: #800080;">2</span></span><span style="color: #000000;"><span style="color: #000000;">); Self.tableViewX.center</span></span>= Cgpointmake (WIDTH/<span style="color: #800080;"><span style="color: #800080;">2</span></span>, (HEIGHT +<span style="color: #800080;"><span style="color: #800080;"></span> -</span>) /<span style="color: #800080;"><span style="color: #800080;">2</span></span>+<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">); Self.tableViewX.dataSource</span></span>=<span style="color: #000000;">self <span style="color: #000000;">; Self.tableviewx.</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Delegate</span></span>=<span style="color: #000000;">self <span style="color: #000000;">; Self.tableViewX.pagingEnabled</span></span>=<span style="color: #000000;"><span style="color: #000000;">YES; Self.tableViewX.showsVerticalScrollIndicator</span></span>=<span style="color: #000000;"><span style="color: #000000;">NO; Self.tableViewX.bounces</span></span>=<span style="color: #000000;"><span style="color: #000000;">YES; [self.view addSubview:self.tableViewX]; }</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">shows a few cells</span></span>-(nsinteger) TableView: (uitableview *<span style="color: #000000;"><span style="color: #000000;">) TableView numberofrowsinsection: (nsinteger) section{</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span> <span style="color: #800080;"><span style="color: #800080;">6</span></span><span style="color: #000000;"><span style="color: #000000;">;}</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Data Interaction</span></span>-(uitableviewcell *) tableView: (uitableview *) tableView cellforrowatindexpath: (nsindexpath *<span style="color: #000000;"><span style="color: #000000;">) indexpath{</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Data</span></span>Nsarray * Newpho = allnewsarray[<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">]; Nsarray</span></span>* Newarr = allnewsarray[<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">]; Nsdictionary</span></span>* Newsphotosdic =<span style="color: #000000;"><span style="color: #000000;">newpho[indexpath.row]; Nsdictionary</span></span>* Newsdic =<span style="color: #000000;"><span style="color: #000000;">newarr[indexpath.row]; Nsarray</span></span>* Photos = [newsphotosdic objectforkey:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Data</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]; NSString</span></span>* Identifier = [nsstring Stringwithformat:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Cell%lu</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, indexpath.row]; YZXVIEWCELLX</span></span>* Cell =<span style="color: #000000;"><span style="color: #000000;">[tableView dequeuereusablecellwithidentifier:identifier]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(Cell = =<span style="color: #000000;"><span style="color: #000000;">Nil) {Cell</span></span>=<span style="color: #000000;"><span style="color: #000000;">[[yzxviewcellx alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier andArray:photos]; } Cell.nowarray</span></span>= [newsdic objectforkey:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Data</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]; Cell.photoarray</span></span>= [newsphotosdic objectforkey:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Data</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]; NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">+++++++++++++++%lu%lu</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, Cell.nowArray.count, Cell.PhotoArray.count); Cell.contentView.transform</span></span>= Cgaffinetransformmakerotation (m_pi/<span style="color: #800080;"><span style="color: #800080;">2</span></span><span style="color: #000000;"><span style="color: #000000;">); Cell.block</span></span>= ^ (yzxviewcellx * newcell, Newslist *<span style="color: #000000;"><span style="color: #000000;">Aa) {NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Details</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); Detailednewscontroller</span></span>* Det =<span style="color: #000000;"><span style="color: #000000;">[[detailednewscontroller alloc] init]; Det. New</span></span>=<span style="color: #000000;"><span style="color: #000000;">aa; [self.navigationcontroller Pushviewcontroller:det animated:yes]; }; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">Cell;}</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">because the transverse tableview instead of scroll, the height is the screen width</span></span>-(cgfloat) tableView: (uitableview *) tableView heightforrowatindexpath: (nsindexpath *<span style="color: #000000;"><span style="color: #000000;">) indexpath{</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">WIDTH;}</span></span></pre><p><p></p></p><p class="p1"><p class="p1"></p></p><p class="p1"><p class="p1"></p></p><p><p>An explanation of the use of TableView in the iOS development UI Chapter</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.