iOS TableVew 侧滑效果~ OC语言~demo

//联系人:石虎  QQ: 1224614774昵称:嗡嘛呢叭咪哄

/**

注意点: 1.看 GIF 效果图.

       2.看连线视图的效果图.

       3.看实现代码(直接复制实现效果).

*/

一、GIF 效果图:



二、连线视图的效果图:

图1:



三、实现代码:


=============

 ======================================


控制器1: ViewController.m

 

//

//  ViewController.m

//  TableVew 侧滑效果~ OC语言

//

//  Created by 石虎 on 2017/8/21.

//  Copyright © 2017 shihu. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>


@property (nonatomic,strong)UITableView *tableView;

@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

    _tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,60,self.view.frame.size.width , self.view.frame.size.height)];

    _tableView.backgroundColor = [UIColororangeColor];

    _tableView.delegate =self;

    _tableView.dataSource =self;

    _tableView.rowHeight =80;

    [self.tableViewregisterClass:[UITableViewCellclass]forCellReuseIdentifier:@"CELL"];

    [self.viewaddSubview:_tableView];

}


#pragma mark -- 数据源方法

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

{

    return10;

}


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

{

    

    // cell 的唯一标识符

    staticNSString *ider =@"CELL";

    //创建 cell

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:iderforIndexPath:indexPath];

    //缓存池

    if (!cell) {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:ider];

    }

    

    //赋值内容

    cell.textLabel.text = [NSStringstringWithFormat:@"row --- %ld",(long)indexPath.row];

    //cell 的背景颜色

    cell.backgroundColor = [UIColoryellowColor];

    return  cell;

}


#pragma mark -- 代理方法

//这个方法就是可以自己添加一些侧滑出来的按钮,并执行一些命令和按钮设置

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnullNSIndexPath *)indexPath

{

    //设置按钮(它默认第一个是修改系统的)

    UITableViewRowAction *actionOne = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"我是第一个"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {

        NSLog(@"我是第一个----->");

        [[[UIAlertViewalloc]initWithTitle:@"提醒"message:@"我是第一个点击成功"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil]

         show];

        

    }];

    //设置按钮(它默认第一个是修改系统的)

    UITableViewRowAction *actionTwo = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"我是第二个"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {

        //执行跳转到下个界面操作

        NSLog(@"我是第二个----->");

        [[[UIAlertViewalloc]initWithTitle:@"提醒"message:@"我是第二个点击成功"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil]

         show];

    }];

    

    actionOne.backgroundColor = [UIColorblueColor];

    actionTwo.backgroundColor = [UIColorredColor];

    

    return@[actionOne,actionTwo];

}

@end


===============

=======


谢谢!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值