iOS UITableView related

Source: Internet
Author: User

TableView implemented methods no grouping of cells

#pragma mark-table View data source-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{    return self.contacts.count;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{    //1. Create cell    Mjcontactcell *cell = [Mjcontactcell Cellwithtableview:tableview];       2. Set the cell data    cell.contact = Self.contacts[indexpath.row];        return cell;}

Refresh of TableView:

* Local Refresh (use premise: Before and after the refresh, the number of model data is unchanged)

-(void) Reloadrows: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;

* Local deletion (use premise: number of model data reduction = = Indexpaths length)
-(void) Deleterowsatindexpaths: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;

The left swipe calls the Commiteditingstyle method Commiteditingstyle to determine whether to add or remove

#pragma Mark-tableview Proxy Method/** * If this method is implemented, it automatically realizes the function of sliding deletion * Click the delete button will call * Commit an edit operation will be called (action: delete \ Add) * @param editingsty Le edit behavior * @param indexpath operation line number */-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelledit Ingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) indexpath{if (Editingstyle = = Uitableviewcelleditingstyledelete) {//Submit a Delete action//1. Delete model data [self.contacts removeObjectAtIndex:indexPath.ro                W]; 2. Refresh the table//partially refresh some rows (using the premise: the number of rows in the model data is constant) [Self.tableview Deleterowsatindexpaths:@[indexpath] Withrowanimation:ui                Tableviewrowanimationtop];    3. Archive [Nskeyedarchiver archiveRootObject:self.contacts Tofile:mjcontactsfilepath];  } else if (Editingstyle = = Uitableviewcelleditingstyleinsert) {//1. Modifying model data Mjcontact *contact = [mjcontact        ALLOC] init];        Contact.name = @ "Jack";        Contact.phone = @ "10086"; [Self.contacts insertobject:contact AtIndex:indexPath.row + 1];        2. Refresh Table Nsindexpath *nextpath = [Nsindexpath IndexPathForRow:indexPath.row + 1 insection:0]; [Self.tableview Insertrowsatindexpaths:@[nextpath] withrowanimation:uitableviewrowanimationbottom];//[    Self.tableview Reloaddata]; }}

Let TableView into edit state

[Self.tableview setediting:!self.tableview.isediting Animated:yes];
When the Editstyleforrowatindexpath is implemented, this method is called when the edit is clicked, which asks the state of the edit
/** *  When TableView enters the edit state, it is called, asking what action each row will take (add \ Delete) */-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) indexpath{    return indexpath.row%2? Uitableviewcelleditingstyledelete:uitableviewcelleditingstyleinsert;}




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.