1. Create uitableview
DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];[DataTable setDelegate:self];[DataTable setDataSource:self];[self.view addSubview:DataTable];[DataTable release];
2. Description of uitableview Methods
// Total number of sections-(nsarray *) sectionindextitlesfortableview :( uitableview *) tableview {return titledata;} // section titles // The title displayed for each section-(nsstring *) tableview :( uitableview *) tableview titleforheaderinsection :( nsinteger) Section {return @ ";} // specifies the number of partitions (sections). The default value is 1-(nsinteger) numberofsectionsintableview :( uitableview *) tableview {return 4;} // specify the number of rows in each partition. The default value is 1-(nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) section {} // Draw Cell-(uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {static nsstring * simpletableidentifier = @ "simpletableidentifier "; uitableviewcell * cell = [tableview identifier: simpletableidentifier]; If (cell = nil) {Cell = [[[uitableviewcell alloc] initwithstyle: Invalid reuseidentifier: simpletableidentifier] autorelease];} cell. imageview. image = image; // The image cell when no cell is selected. imageview. highlightedimage = highlightimage; // The image cell after the cell is selected. TEXT = //..... return cell;} // line indent-(nsinteger) tableview :( uitableview *) tableview indentationlevelforrowatindexpath :( nsindexpath *) indexpath {nsuinteger ROW = [indexpath row]; return row ;} // change the Row Height-(cgfloat) tableview :( uitableview *) tableview heightforrowatindexpath :( nsindexpath *) indexpath {return 40;} // locate [topicstable setcontentoffset: cgpointmake (0, promisenum * 44 + chapter * 20)]; // return the current selected cellnsindexpath * IP = [nsindexpath indexpathforrow: Row insection: section]; [topicstable selectrowatindexpath: IP animated: Yes scrollposition: response]; [tableview setseparatorstyle: Response]; // selected cell response event-(void) tableview :( uitableview *) tableview didselectrowatindexpath :( nsindexpath *) indexpath {[tableview deselectrowatindexpath: indexpath animated: yes]; // The reversed color after selection disappears instantly} // determine the selected row (to prevent the first row from being selected)-(nsindexpath *) tableview :( uitableview *) tableview willselectrowatindexpath :( nsindexpath *) indexpath {nsuinteger ROW = [indexpath row]; If (ROW = 0) return nil; return indexpath ;} // indicates whether the cell del button appears-(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 on the right-(nsarray *) sectionindextitlesfortableview :( uitableview *) tableview {} // return section title content-(nsstring *) tableview :( uitableview *) tableview titleforheaderinsection :( nsinteger) Section {}// the content of the del button when a custom stroke occurs-(nsstring *) tableview :( uitableview *) Configure :( nsindexpath *) indexpath // jump to the specified row or section [tableview scrolltorowatindexpath: [nsindexpath indexpathforrow: 0 insection: 0] atscrollposition: uitableviewscrollpositionbottom animated: No];
3. Create uilable multi-line display on uitableviewcell
-(Uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {static nsstring * handle = @ "cell"; uitableviewcell * cell = [tableview progress: cellidentifier]; if (cell = nil) {Cell = [[[uitableviewcell alloc] initwithframe: cgrectzero reuseidentifier: identifier] autorelease]; 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 = cell; return cell;} // The color typedef Enum {Cell, cell, uitableviewcellselectionstylegray} uitableviewcellselectionstyle // The format of the cell button on the right is typedef Enum {uitableviewcellaccessorynone, // 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 a line break typedef Enum {uitableviewcellseparatorstylenone, category} uitableviewcellseparatorstyle // change the line feed color tableview. separatorcolor = [uicolor bluecolor];