IOS TableView Detailed
Last Update:2016-02-15
Source: Internet
Author: User
<span id="Label3"></p><p><p>I. Establishment of UITableView</p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre><pre>DataTable = [[uitableview alloc] initwithframe:cgrectmake (0, 0, 320, 420)]; [DataTable setdelegate:self]; [DataTable setdatasource:self]; [self.view addsubview:datatable]; [DataTable release];</pre></pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p>second, UITableView Each method description</p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre>Total Sections-(nsarray *) sectionindextitlesfortableview: (uitableview *) tableview{return titledata;} Section titles//the title displayed for each section-(nsstring *) tableView: (uitableview *) tableView titleforheaderinsection: (nsinteger ) Section{return @ "";} Specify how many partitions (section), default to 1-(nsinteger) numberofsectionsintableview: (uitableview *) tableView {return 4;} Specify how many rows are in each partition, default to 1-(nsinteger) tableView: (uitableview *) tableView numberofrowsinsection: (nsinteger) section{}// Draw Cell-(uitableviewcell *) tableView: (uitableview *) tableView cellforrowatindexpath: (nsindexpath *) indexpath {static NSString *simpletableidentifier = @ "simpletableidentifier"; UITableViewCell *cell = [tableView dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell = = Nil) {cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier] autorelease]; Cell.imageview.image=image;//picture Cell.image When the cell is not selectedView.highlightedimage=highlightimage;//select the cell after the picture cell.text=//.... return cell;} Line Indent-(nsinteger) tableView: (uitableview *) tableView indentationlevelforrowatindexpath: (nsindexpath *) indexpath{ Nsuinteger row = [indexpath row]; Return row;} Change the height of the row-(cgfloat) tableView: (uitableview *) tableView heightforrowatindexpath: (nsindexpath *) indexpath{return 40;} Locate [topicstable setcontentoffset:cgpointmake (0, promisenum * + Chapter * 20)];//returns the currently selected Cellnsindexpath *ip = [nsindexp Ath Indexpathforrow:row insection:section]; [topicstable Selectrowatindexpath:ip Animated:yes scrollposition:uitableviewscrollpositionnone]; [tableView setseparatorstyle:uitableviewcellselectionstylenone];//selected Cell response event-(void) tableView: (uitableview *) TableView didselectrowatindexpath: (nsindexpath *) indexpath{[tableView deselectrowatindexpath:indexpath animated: Yes];//the selected inverse color disappears immediately}//the selected row (prevents the first row from being Selected)-(nsindexpath *) tableView: (uitableview *) tableView Willselectrowatindexpath :(nsindexpath *) Indexpath{nsuinteger row = [iNdexpath row]; if (row = = 0) return nil; Return indexpath;} Scrub cell If the Del button is Present-(BOOL) tableView: (uitableview *) tableView caneditrowatindexpath: (nsindexpath *) indexpath {}// Edit Status-(void) tableView: (uitableview *) tableView commiteditingstyle: (uitableviewcelleditingstyle) Editingstyleforrowatindexpath: (nsindexpath *) indexpath{}[topicstable setcontentsize:cgsizemake (0, Controller.promisenum * 44) add an index table to the right Of];//-(nsarray *) sectionindextitlesfortableview: (uitableview *) tableview{}// Returns section header content-(nsstring *) tableView: (uitableview *) tableView titleforheaderinsection: (nsinteger) section{}// Custom Scrub del button content-(nsstring *) tableView: (uitableview *) tableviewtitlefordeleteconfirmationbuttonforrowatindexpath: ( Nsindexpath *) Indexpath//jumps to the referring row or Section[tableview Scrolltorowatindexpath:[nsindexpath indexpathforrow:0 insection:0] Atscrollposition:uitableviewscrollpositionbottom animated:no];</pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p>third, the establishment of uilable multi-line display on UITableViewCell</p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre>-(uitableviewcell *) tableView: (uitableview *) tableView cellforrowatindexpath: (nsindexpath *) indexpath {static Nsstri ng *cellidentifier = @ "Cell"; UITableViewCell *cell = [tableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = Nil) {cell = [[[uitableviewcell alloc] initwithframe:cgrectzero reuseidentifier:cellidentifier] Autore lease]; UILabel *datalabel = [[UILabel alloc] initwithframe:cgrectmake (10, 0, 320, 44)]; [datalabel settag:100]; Datalabel.autoresizingmask = Uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight; [cell.contentview addsubview:datalabel]; [datalabel release]; } UILabel *datalabel = (UILabel *) [cell.contentview viewwithtag:100]; [datalabel Setfont:[uifont boldsystemfontofsize:18]; Datalabel.text = [data. DataArray objectAtIndex:indexPath.row]; Cell.accessorytype = uitableviewcellaccessorydisclosureindicator; Return cell;} color typedef enum {uitableviewcellselectionstylenone, Uitableviewcellse when cell is selectedlectionstyleblue, uitableviewcellselectionstylegray} Uitableviewcellselectionstyle//cell Right button format typedef enum {UITABL Eviewcellaccessorynone,//don ' t show any accessory view uitableviewcellaccessorydisclosureindicator, Regular Chevron. Doesn ' t track uitableviewcellaccessorydetaildisclosurebutton,//blue button W/chevron. Tracks Uitableviewcellaccessorycheckmark//checkmark. Doesn ' t track} uitableviewcellaccessorytype//whether to add newline typedef enum {uitableviewcellseparatorstylenone, UITableViewCell separatorstylesingleline} Uitableviewcellseparatorstyle//change Line Line Color Tableview.separatorcolor = [UIColor blueColor];</pre><p><p></p></p><p><p>IOS TableView Detailed</p></p></span>