Common methods in IOS, Uitableviewdatasource, and uitableviewdelegate protocols

Source: Internet
Author: User


common methods in Uitableviewdatasource protocol

1. Set the right side Index Value

-(nsarray *) Sectionindextitlesfortableview: ( UITableView *) TableView

2. set up grouping identities

-(nsstring *) TableView: ( UITableView *) TableView titleforheaderinsection: (nsinteger) section


3.set Number of groups
- (Nsinteger) Numberofsectionsintableview: (UITableView*) TableView

4. Set the number of rows

-(nsinteger) TableView: ( UITableView *) TableView numberofrowsinsection: (nsinteger) section

5.Createcell (using the reuse mechanism, as in the following example)
- (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) Indexpath
{
1.creating a reuse identifier
   StaticNSString*identifier =@ "Reuse";

2. go to the reuse queue to take reusable cells from identifiers

Addressbookcell *cell = [TableViewdequeuereusablecellwithidentifier: Identifier];

3. determine whether to obtain a reusable cell ( finally space free )

if (!cell) {

cell = [[[addressbookcellalloc]initwithstyle: Uitableviewcellstyledefaultreuseidentifier: identifier]autorelease ];

}

return cell;
}
6.SetTableViewthe edit state of each row(YES, editable)
- (BOOL) TableView: (UITableView*) TableView Caneditrowatindexpath: (Nsindexpath*) Indexpath
{
return YES
}

7.edit button's Click event ( triggered when the edit button is clicked )

-(void) setediting: ( BOOL ) Editing animated: (BOOL) animated


8. Triggers when an edit operation is committed

-(void) TableView: ( UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath :(nsindexpath *) Indexpath

9. Set tableView If each row is allowed to move (YES, movable)

-(BOOL) TableView: ( UITableView *) TableView Canmoverowatindexpath: (nsindexpath *) Indexpath

{
return YES
}

triggering after committing a move operation

-(void) TableView: ( UITableView *) TableView Moverowatindexpath: (nsindexpath *) Sourceindexpath Toindexpath: ( Nsindexpath *) Destinationindexpath


common methods in Uitableviewdelegate protocol

1. Set the row height

-(cgfloat) TableView: ( UITableView *) TableView Heightforrowatindexpath: (nsindexpath *) Indexpath

{
return;
}

2. trigger When cell is selected

-(void) TableView: ( UITableView *) TableView Didselectrowatindexpath: (nsindexpath *) Indexpath

3. set the edit style for Tableviewcell ( insert / Delete )

-(uitableviewcelleditingstyle) TableView: ( UITableView *) TableView Editingstyleforrowatindexpath: (nsindexpath *) Indexpath

4. set the text shown above when you click the Edit button , such as show delete

-( nsstring Span style= "font:18.0px Menlo" > *) TableView: ( uitableview *) TableView Titlefordeleteconfirmationbuttonforrowatindexpath: ( Span style= "color: #6122ae; font:18.0px Menlo ">nsindexpath *) Indexpath ns_available_ios ( 3 _0) {    return @ " delete " ;}


5. Set the cell Move location

-(nsindexpath *) TableView: ( UITableView *) TableView Targetindexpathformovefromrowatindexpath: (nsindexpath *) Sourceindexpath Toproposedindexpath: (nsindexpath *) Proposeddestinationindexpath

Common methods in IOS, Uitableviewdatasource, and uitableviewdelegate protocols

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.