您的位置:首页 > 编程语言 > C语言/C++

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

2017-08-21 11:51 387 查看
//联系人:石虎 
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

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

=======

谢谢!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息