Tableciew的基本属性和侧滑(删除 置顶 更多)

#import <UIKit/UIKit.h>

//使用tableview必须遵循的

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

@property(strong,nonatomic) UITableView *tableview;

//数据源

@property(strong,nonatomic) NSArray *students;

@end

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

//    1.数据源

[email protected][@"dfsa",@"daf",@"dasf"];

//    tableview 初始化 指定样式

self.tableview=[[UITableView alloc]initWithFrame:self.view.frame style:1];

//    3.指定代理

self.tableview.delegate=self;

self.tableview.dataSource=self;

//表格分隔符的颜色

self.tableview.separatorColor=[UIColor redColor];

//    指定重用单元格的唯一标识

[self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

//    4.添加到view上

[self.view addSubview:self.tableview];

}

//设置显示分区数量

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;

}

#pragma mark 数据源 每个分区显示行数设置

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

{

return self.students.count;

}

#pragma mark 每个单元格显示的内容

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

{

static NSString *[email protected]"cell";

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentity forIndexPath:indexPath];

cell.textLabel.text=self.students[indexPath.row];

return cell;

//    return [UITableViewCell new];

}

#pragma mark 代理方法 显示选中行的单元格信息

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

NSLog(@"%@",self.students[indexPath.row]);

}

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

{

return YES;

}

//侧滑 删除 置顶  更多 按钮

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewRowAction *layTopRowAction1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

NSLog(@"点击了删除");

[tableView setEditing:NO animated:YES];

}];

layTopRowAction1.backgroundColor = [UIColor redColor];

UITableViewRowAction *layTopRowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"置顶" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

NSLog(@"点击了置顶");

[tableView setEditing:NO animated:YES];

}];

layTopRowAction2.backgroundColor = [UIColor greenColor];

UITableViewRowAction *layTopRowAction3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

NSLog(@"点击了更多");

[tableView setEditing:NO animated:YES];

}];

layTopRowAction3.backgroundColor = [UIColor blueColor];

NSArray *arr = @[layTopRowAction1,layTopRowAction2,layTopRowAction3];

return arr;

}

时间: 2024-08-27 15:04:41

Tableciew的基本属性和侧滑(删除 置顶 更多)的相关文章

滑动cell 显示的按钮 类型分别是 删除 置顶 其他

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { //删除按钮 UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:

给UITableView的侧滑删除增加多个按钮

一. 需求: cell的侧滑删除默认只有一个删除按钮, 给侧滑添加多个按钮, '删除', '置顶', '更多'. 二. 实现说明: 1) 我们在使用一些应用的时候,在滑动一些联系人的某一行的时候,会出现删除.置顶.更多等等的按钮,在iOS8之前,我们都需要自己去实现.但是到了iOS8,系统已经写好了,只需要一个代理方法和一个类就搞定了 2) iOS8的协议多了一个方法,返回值是数组的tableView:editActionsForRowAtIndexPath:方法,我们可以在方法内部写好几个按钮

iOS 如何设置tableview列表的cell上的的设置删除键 、置顶按钮、 未读信息按钮

思路很重要! 主要是写下我实现的具体思想,效果:首先,将cell向左滑动的时候,就会出现 删除  置顶 等按钮,那么我们就可以设计在cell上加两层的控件,第一层放的便是你要添加的 删除  置顶 等按钮  ,把这些按钮布置在cell的右侧  然后在第二层就是放一个uiview 这个uiview大小和cell的大小一样  然后再到uiview上添加一些显示数据的控件.  问题: 那第一层的 删除和置顶等按钮不是被覆盖了吗?  对 要的就是这种效果,现在的解决思路就是在uiview 上添加一个 pa

QQ好友列表向左滑动出现置顶、删除--第三方开源--SwipeMenuListView

SwipeMenuListView是在github上的第三方开源项目,该项目在github上的链接地址是:https://github.com/baoyongzhang/SwipeMenuListView . 下载后直接将项目包复制粘贴到需要的项目当中: 测试代码: item.xml: 1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="htt

左滑菜单(删除、置顶)

<div class="xinzhibox"> <div class="list"> <div class="xinzhilist" tapmode onclick="openlist('数字化商业')"> <div class="imgbox"> <img src="../image/news/img.png" alt="

【Android】史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS

本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 转载请标明出处: http://blog.csdn.net/zxt0601/article/details/53157090 本文出自:[张旭童的博客](http://blog.csdn.net/zxt0601) 代码传送门:喜欢的话,随手点个star.多谢 https://github.com/mcxtzhang/SwipeDelMenuLayout 重要的话 开头说,not for the RecyclerView or L

史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。

重要的话 开头说,not for the RecyclerView or ListView, for the Any ViewGroup. 本控件不依赖任何父布局,不是针对 RecyclerView.ListView,而是任意的ViewGroup里的childView都可以使用侧滑(删除)菜单.支持任意ViewGroup.0耦合.史上最简单. 概述 本控件从撸出来在项目使用至今已经过去7个月,距离第一次将它push至github上,也已经2月+.(之前,我发表过一篇文章.传送门:http://b

自定义控件进阶02_侧滑删除,粘性控件

1 快速索引 细节问题: 1.1 把当前被选中的字母索引置为灰色,否则为白色 每一次在快速索引栏上的触摸事件都触发invalidate(),重走onDraw()方法 在onDraw()方法里,做判断,如果通过触摸事件计算的索引与绘制字母数组的索引一致时就更改画笔的颜色,(记得在触摸事件中如果手指抬起,就把计算的索引置为-1) 1.2 弹出吐司不太好看,弹出一个圆角的矩形框会好看一些(实际上就是一个圆角的TextView,平常隐藏,滑动的时候显示) 圆角:定义背景的xml文件,shape根节点,弧

2016.5.30实现透明Panel及控件置顶的方法

想放置一个透明Panel在某控件上端,实现效果是可透过此Panel看见下面控件,但鼠标点击却无任何反应. 1.新建置自定义Panel类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; namespace NavDataManager { public class MyTran