UITableView detailed ()

Source: Internet
Author: User

(originally took to D a l public number) UITableView detailedI. Establishment of UITableView


DataTable = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, 320, 420)];

[DataTable setdelegate:self];

[DataTable setdatasource:self];

[Self.view addsubview:datatable];

[DataTable release];

Second, UITableView each method description

Section Total title

-(Nsarray *) Sectionindextitlesfortableview: (UITableView *) tableview{

return titledata;

}

Section Titles

Title for each section display

-(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 When a cell is not selected

cell.imageview.highlightedimage=highlightimage;//the picture after the cell is selected

cell.text=//.....

return cell;

}

Line Indent

-(Nsinteger) TableView: (UITableView *) TableView Indentationlevelforrowatindexpath: (Nsindexpath *) indexpath{

Nsuinteger row = [Indexpath row];

return row;

}

Change the height of a row

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{

return 40;

}

Positioning

[Topicstable setcontentoffset:cgpointmake (0, Promisenum * + Chapter * 20)];

Returns the currently selected cell

Nsindexpath *ip = [Nsindexpath indexpathforrow:row insection:section];

[Topicstable Selectrowatindexpath:ip Animated:yes Scrollposition:uitableviewscrollpositionnone];

[TableView Setseparatorstyle:uitableviewcellselectionstylenone];

Select cell Response Event

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{

[TableView deselectrowatindexpath:indexpath animated:yes];//color disappears immediately after selection

}

Judging 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 appears

-(BOOL) TableView: (UITableView *) TableView Caneditrowatindexpath: (Nsindexpath *) Indexpath {

}

Edit State

-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle

Forrowatindexpath: (Nsindexpath *) Indexpath

{



[Topicstable setcontentsize:cgsizemake (0,controller.promisenum * 44)];

Add an index table to the right

-(Nsarray *) Sectionindextitlesfortableview: (UITableView *) tableview{

}

Return section header content

-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (Nsinteger) section{

}

The contents of the Del button when customizing the scrub

-(NSString *) TableView: (UITableView *) TableView

Titlefordeleteconfirmationbuttonforrowatindexpath: (Nsindexpath *) Indexpath

Jump to the referring row or section

[TableView scrolltorowatindexpath:[nsindexpath indexpathforrow:0 insection:0] Atscrollposition: Uitableviewscrollpositionbottom Animated:no];

Third, the establishment of uilable multi-line display on UITableViewCell

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {

static NSString *cellidentifier = @ "Cell";

UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];

if (cell = = nil) {

cell = [[[UITableViewCell alloc] Initwithframe:cgrectzero reuseidentifier:cellidentifier] 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 = Uitableviewcellaccessorydisclosureindicator;

return cell;

}

Color when cell is selected

typedef enum {

Uitableviewcellselectionstylenone,

Uitableviewcellselectionstyleblue,

Uitableviewcellselectionstylegray

} Uitableviewcellselectionstyle

Cell Right button format

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 line breaks

typedef enum {

Uitableviewcellseparatorstylenone,

Uitableviewcellseparatorstylesingleline

} uitableviewcellseparatorstyle//Change Line line Color

Tableview.separatorcolor = [Uicolor bluecolor];


Sweep
Follow the public number

UITableView detailed ()

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.