UITableView的常用代理方法
2016-04-18 14:13
561 查看
//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
return 80;
}
//分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 3;
}
//设置每个区有多少行共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
//设置区域的名称
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
{
return @"123";
}
//是否允许行移动
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//响应点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSLog(@"响应单击事件");
}
//小按钮的响应事件
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"accessoryButton的响应事件");
}
//删除按钮的名字
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}
//设置滑动,
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
//ruturn NO不实现滑动
return YES;
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"手指撮动了");
return UITableViewCellEditingStyleDelete;
// //插入
// return UITableViewCellEditingStyleInsert;
}
设置CELL的样式
// cell.selectionStyle = UITableViewCellSelectionStyleBlue;
//灰色
// cell.selectionStyle = UITableViewCellSelectionStyleGray;
//无颜色
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
//向右箭头样式
// cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//向右箭头button
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
UITableViewCellStyleDefault,// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x)
UITableViewCellStyleValue1,// Left aligned label on left and right aligned label on right with blue text (Used in Settings)
UITableViewCellStyleValue2,// Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)
UITableViewCellStyleSubtitle
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
return 80;
}
//分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 3;
}
//设置每个区有多少行共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
//设置区域的名称
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
{
return @"123";
}
//是否允许行移动
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//响应点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSLog(@"响应单击事件");
}
//小按钮的响应事件
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"accessoryButton的响应事件");
}
//删除按钮的名字
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}
//设置滑动,
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
//ruturn NO不实现滑动
return YES;
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"手指撮动了");
return UITableViewCellEditingStyleDelete;
// //插入
// return UITableViewCellEditingStyleInsert;
}
设置CELL的样式
// cell.selectionStyle = UITableViewCellSelectionStyleBlue;
//灰色
// cell.selectionStyle = UITableViewCellSelectionStyleGray;
//无颜色
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
//向右箭头样式
// cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//向右箭头button
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
UITableViewCellStyleDefault,// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x)
UITableViewCellStyleValue1,// Left aligned label on left and right aligned label on right with blue text (Used in Settings)
UITableViewCellStyleValue2,// Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)
UITableViewCellStyleSubtitle
相关文章推荐
- AVI Player with Playmaker actions 使用UGUI显示视频以及控制播放视频 (二)
- 理解 Android Build 系统
- AndroidUI--SlidingMenu使用例子
- IOS-UITableView入门(2)
- 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI
- 原生的强大DOM选择器querySelector
- String、StringBuffer和StringBuilder的区别
- 南京理工大学第八届程序设计大赛(校外镜像) F sequence
- APUE阅读笔记(八)——进程控制
- 南京理工大学第八届程序设计大赛(校外镜像) - sequence (贪心)
- Druid基本使用配置以及如何查看sql信息监控日志
- IOS开发之001 控件类 UIlabel全解
- IOS开发之小实例--使用UIImagePickerController创建一个简单的相机应用程序
- 【Arduino官方教程第一辑】示例程序 1-5 LED亮度渐隐
- Android Stuidio解决更新下载时无法连接URL的问题
- Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextE
- Easyui datagrid editor为combobox时指定数据源
- querySelector 和 querySelectorAll 的使用
- require.js的用法
- UIView的图像填充模式