iOS crazy detailed TableView edit add delete

Source: Internet
Author: User

//
Vkowlaccountvc.m
Pocketuniversity
//
Created by long on 15-1-14.
Copyright (c) 2015 Wlong. All rights reserved.
//

#import "VkoWLAccountVC.h"
#import "VkoWLMoreTableViewCell.h"

#define Kicoarray @[@ "message" @ "account" @ "Copyright"
#define Ktitlearray @[@ "handset mode" @ "Play" @ "clear Cache"]

@interface VKOWLACCOUNTVC ()
{
The current editing mode
Uitableviewcelleditingstyle _editingstyle;
Nsmutablearray *_icoarray;
Nsmutablearray *_titlearray;
}
@end

@implementation VKOWLACCOUNTVC

-(void) Viewdidload {
[Super Viewdidload];
Do any additional setup after loading the view.

_icoarray = [Nsmutablearray Arraywitharray:kicoarray];
_titlearray = [Nsmutablearray Arraywitharray:ktitlearray];


[Self navtitle:@ "account Management" leftbuttonhidden:no];

[Self createview];

_editingstyle = Uitableviewcelleditingstyledelete;

}

-(void) CreateView
{
_tableview = [[UITableView alloc] Initwithframe:cgrectmake (0, Self.bgImageView.bottom, kuiscreenwidth, [self Getmiddleviewhight]) style: (uitableviewstylegrouped)];
_tableview.delegate = self;
_tableview.datasource = self;
_tableview.allowsselectionduringediting = YES; You can select the edit state
[Self.view Addsubview:_tableview];


Self.rightButton.hidden = NO;
Self.rightButton.backgroundColor = [Uicolor Clearcolor];
[Self.rightbutton setimage:[uiimage imagenamed:@ "edit"] forstate: (UIControlStateNormal)];
[Self.rightbutton addtarget:self Action: @selector (Editbuttonclick:) forControlEvents: (uicontroleventtouchupinside )];
}

-(void) Editbuttonclick: (UIButton *) button
{
[Self deleteData];
}


#pragma mark---uitableview back to cell---
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
static NSString *cellidentifier = @ "Vkowlmoretableviewcell";

Vkowlmoretableviewcell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];

if (cell = = nil) {

cell = [[Vkowlmoretableviewcell alloc] Initwithstyle: (uitableviewcellstylesubtitle) Reuseidentifier:cellidentifier] ;

}

Cell.selectionstyle = Uitableviewcellselectionstylenone;
Cell.iocImageView.image = [UIImage Imagenamed:_icoarray[indexpath.row]];
Cell.labelTitle.text = _titlearray[indexpath.row];
[Cell.iocImageView.layer Setmaskstobounds:yes];
[Cell.iocImageView.layer SETCORNERRADIUS:25/2];
Cell.arrowImageView.hidden = YES;


return cell;

}

#pragma mark---tableView dataSource---
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
{
return _titlearray.count;
}

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView
{
return 1;
}

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath
{
return 20+25;
}

#pragma mark---Check the jump to details screen---
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
{

}


#pragma mark---deit delete---
Turn UITableView and Uiviewcontroller into editable states
-(void) setediting: (BOOL) editing animated: (BOOL) animated
{
[Super Setediting:editing animated:animated];

[_tableview setediting:editing animated:animated];
}

Specify which row can edit which line cannot be edited
-(BOOL) TableView: (UITableView *) TableView Caneditrowatindexpath: (Nsindexpath *) Indexpath
{
return YES;
}

Sets which line of Edit button state specifies the edit style
-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) Indexpath
{
return _editingstyle;
}

Determine the style of clicking a button to add or remove
-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) Indexpath
{
Deleted actions
if (Editingstyle = = Uitableviewcelleditingstyledelete) {

[_titlearray RemoveObjectAtIndex:indexPath.row];
[_icoarray RemoveObjectAtIndex:indexPath.row];


Nsarray *indexpaths = @[indexpath]; An array of the number of rows at the build index
The method to delete an index is followed by an animated style
[_tableview deleterowsatindexpaths:indexpaths withrowanimation: (Uitableviewrowanimationleft)];

}

Actions added
if (Editingstyle = = Uitableviewcelleditingstyleinsert) {

Nsarray *indexpaths = @[indexpath];
[_tableview insertrowsatindexpaths:indexpaths withrowanimation: (uitableviewrowanimationright)];

}

}

#pragma mark Delete data
-(void) DeleteData
{
_editingstyle = Uitableviewcelleditingstyledelete;

BOOL isediting = self.tableView.isEditing;

[Self.tableview setediting:!isediting Animated:yes];
}

-(void) AddData
{
_editingstyle = Uitableviewcelleditingstyleinsert;

BOOL isediting = self.tableView.isEditing;

[Self.tableview setediting:!isediting Animated:yes];
}

-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}

/*
#pragma mark-navigation

In a storyboard-based application, you'll often want to do a little preparation before navigation
-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {
Get The new view controller using [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
}
*/

@end




更多iOS疯狂详解:http://blog.csdn.net/wanglongblog

iOS crazy detailed TableView edit add delete

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.