Edit Uitableviewcell--editing

Source: Internet
Author: User

    Self.navigationItem.rightBarButtonItem = Self.editbuttonitem;
-(void) setediting: (BOOL) editing animated: (BOOL) animated{    [Super setediting:editing animated: Animated];    [Self.countriestableview setediting:editing animated:animated];}
-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) indexpath{    if (Editingstyle = =  Uitableviewcelleditingstyledelete) {        * delegatecountry = Self.countries[indexpath.row];        [Self.countries Removeobject:delegatecountry];                [Self.countriestableview Deleterowsatindexpaths:[nsarray Arraywithobject:indexpath] WithRowAnimation: Uitableviewrowanimationautomatic];}    }

Insert (the default editing style is Uitableviewcelleditingstyledelete), so add the insert style.

-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *  ) indexpath{    if ((indexpath.row%20) {        return  Uitableviewcelleditingstyleinsert;    }     return Uitableviewcelleditingstyledelete;}
}Else if(Editingstyle = =Uitableviewcelleditingstyleinsert) {Country* Copiedcountry =Self.countries[indexpath.row]; Country* Newcountry =[[Country alloc] init]; Newcountry.name=Copiedcountry.name; Newcountry.flag=Copiedcountry.flag; Newcountry.capital=Copiedcountry.capital; Newcountry.motto=Copiedcountry.motto; [Self.countries insertobject:newcountry AtIndex:indexPath.row+1]; [Self.countriestableview insertrowsatindexpaths:[nsarray Arraywithobject:[nsindexpath IndexPathForRow: Indexpath.row+1InSection:indexPath.section]]    Withrowanimation:uitableviewrowanimationright]; }

Re-order

-(BOOL) TableView: (UITableView *) TableView Canmoverowatindexpath: (Nsindexpath *) indexpath{    return  YES;}
-(void) TableView: (UITableView *) TableView Moverowatindexpath: (Nsindexpath *) Sourceindexpath Toindexpath: ( Nsindexpath *) destinationindexpath{    [Self.countries exchangeObjectAtIndex:sourceIndexPath.row WithObjectAtIndex:destinationIndexPath.row];    [Self.countriestableview reloaddata];}

Edit Uitableviewcell--editing

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.