美文网首页
cell的滑动删除功能

cell的滑动删除功能

作者: 高乔人 | 来源:发表于2017-06-05 13:51 被阅读23次

#define xhwScreenW [UIScreen mainScreen].bounds.size.width

#define xhwScreenH [UIScreen mainScreen].bounds.size.height

#import "CarNumberTableViewController.h"

@interface CarNumberTableViewController ()

@property (nonatomic,strong) NSMutableArray *mArray;

@end

@implementation CarNumberTableViewController

- (void)viewDidLoad {

[super viewDidLoad];

_mArray = [NSMutableArray arrayWithArray:@[@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥",@"钢筋水泥"]];

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, xhwScreenW, 60)];

searchBar.backgroundColor = [UIColor grayColor];

searchBar.placeholder = @"这里搜索";

[self.view addSubview:searchBar];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return _mArray.count;

}

#pragma mark - 行高

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 46;

}

#pragma mark - cell内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *indefier = @"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indefier];

if (!cell) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indefier];

}

cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.textLabel.text = _mArray[indexPath.row];

return cell;

}

//最后,实现UITableView的一些代理方法

//先要设Cell可编辑

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

return YES;

}

//定义编辑样式

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

return UITableViewCellEditingStyleDelete;

}

//进入编辑模式,按下出现的编辑按钮后,进行删除操作

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

if (editingStyle == UITableViewCellEditingStyleDelete) {

[_mArray removeObjectAtIndex:indexPath.row];

// Delete the row from the data source.

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

}

//修改编辑按钮文字

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{

return @"删除";

}

/*

// Override to support rearranging the table view.

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {

}

*/

/*

// Override to support conditional rearranging of the table view.

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {

// Return NO if you do not want the item to be re-orderable.

return YES;

}

*/

/*

#pragma mark - Navigation

// In a storyboard-based application, you will 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

相关文章

  • cell的滑动删除功能

    #define xhwScreenW [UIScreen mainScreen].bounds.size.widt...

  • 10.12 UITableView2 (cell) 动画效

    UITableView2(cell) 添加一行cell,删除一行cell 向左滑动出现Delete删除键 在点击的...

  • 删除某行 cell

    didSelectRowAtIndexPath 你是要怎么个删除法。是要实现滑动cell出现删除按钮,然后点击删除...

  • cell的自定义删除

    当cell中包含间隔区域时,使用系统默认滑动删除样式,会发现删除按钮会占位间隔区。 在自定义cell中覆盖方法:

  • 关于自定义cell删除效果

    首先分析一下系统cell删除的效果 1、手指轻轻划过和手指拖动,都能滑动视图露出删除按钮2、视图滑动结束有回弹效果...

  • swift中滑动删除cell,自定义删除按钮

    目前正在探索swift的开发,一边学习,一边敲。今天在翻译以前用OC开发的项目时,遇到了滑动删除cell的功能,这...

  • cell滑动删除的那些事

    1.首先创建tableTest,并初始化可变数组arr. #pragma mark 懒加载初始化table - (...

  • 不被干扰的NSTimer

    当timer被添加在cell上时,滑动cell会造成timer失效,因为cell的滑动(UITrackingRun...

  • tableView滑动删除返回错误

    测试提了一个bug,说滑动cell显示删除按钮的状态下,点击返回,执行了“popviewcontroller”,竟...

  • UITableView左划删除cell

    左划删除分为三个步骤:第一步:设置cell可编辑状态为删除状态 第二步:设置滑动后显示的字为@“删除” 第三步:删除

网友评论

      本文标题:cell的滑动删除功能

      本文链接:https://www.haomeiwen.com/subject/ajmifxtx.html