IOS uitableview代理方法

#pragma mark - Table View
//设置section的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
//设置每个section 的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [dataArryList count];
}
//对每个TableViewCell进行操作  UITableView中显示的每一个单元都是一个UITableViewCell对象,其初始化函数initWithStyle:reuseIdentifier:在tableView快速滑动的滑动的过程中,频繁的alloc对象是比较费时的///,于是引入了cell的重用机制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString* cellIdentifier = @"cell";
   
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell== nil) {
        cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] ;
    }
    cell.textLabel.text=[dataArryList objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.dataArryList removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        [self.dataArryList insertObject:@"456" atIndex:indexPath.row];
        [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }
}

//设置UITableView行缩进
-(NSInteger)tableView:(UITableView*)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
  NSUInteger row = [indexPath row];
  return row;
}
//设置cell行间隔的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
//设置选中Cell的响应事件
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}
//设置选中的行所执行的动作
-(NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    return indexPath;
}
//设置划动cell是否出现del按钮,可供删除数据里进行处理
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
}
//设置删除时编辑状态
-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
{

时间: 2024-08-01 13:20:34

IOS uitableview代理方法的相关文章

iOS UITableView代理方法详解

原 iOS UITableView代理方法详解 IOS UITableView的代理方法详解(http://my.oschina.net/u/2340880/blog/404958) 一.补充 在上一篇博客中,http://my.oschina.net/u/2340880/blog/404605,我将IOS中tableView(表视图)的一些常用方法总结了一下,这篇将tableView的代理方法作了总结,对上一篇博客进行了补充. 二.UITableViewDataSourc(数据源代理) 1.必

IOS UITableview代理方法总结

tableview的datasource代理 @required的两个数据源方法 1.返回每个 session 中 cell 的个数 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 2.创建tableviewCell(注意复用) - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtI

iOS textfield代理方法调用的先后顺序(转)

查看原文 今天通过自己的学习把textfield的代理方法全部罗列出来,先后调用顺序做了一下验证. 操作方法是,打开界面-->点击textField-->输入'abc'-->点击'x'清除按钮-->点击键盘'换行'-->点击'完成' log日志: 4 2 4 1 1 1 5 7 6 3 #pragma mark - textField delegate - (BOOL)textField:(UITextField *)textField shouldChangeCharact

iOS UIScrollview代理方法

方法&&属性: // 监控目前滚动的位置(默认CGPointZero) CGPoint contentOffset; - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // 滚动范围的大小(默认CGSizeZero) CGSize contentSize; // 视图在scrollView中的位置(UIEdgeInsetsZero) UIEdgeInsets contentInset; // 设

iOS UITableView的分割线短15像素,移动到最左边的方法(iOS8)

有好几个朋友问我ios 分割线端了一些 如何解决,于是我就写一篇博客吧.为什么我说是少了15像素呢?首先我们拖拽一个默认的tableview 控件! 看下xcode5 面板的inspector(检查器)我们可以找到一个 Separator Insetss 标签 默认是 Default我们选择一下 发现有个Custom 这时候我们惊奇的发现Left 15 ,这时候我们只要把这个 15 改成 0 , 然后保存, 你就会发现tableview 的分割线跟以前一样了. 有些朋友问了如果是代码写的tabl

抽取UITableView的DataSource代理方法及同一份View能接受不同模型数据

View controllers 通常是 iOS 项目中最大的文件,并且它们包含了许多不必要的代码.所以 View controllers 中的代码几乎总是复用率最低的.比如UITableView常规用法如下: 传统使用方法 1. 定义数据模型 @interface LFPhoto : NSObject @property (nonatomic,copy) NSString *name; @property (nonatomic,copy) NSString *title; @end 2. 设计

iOS 设计中关于UIScrollViewDelegate的几个代理方法的简单介绍

在ios设计的过程中,对于UIScrollView这个控件对于开发者而言都不会陌生,在处理UI界面的时候我们经常会用到UIScrollView,既然用到了UIScrollView,那么UIScrollView的几个代理方法就无法避免的被使用了.本文并不介绍UIScrollView的相关属性,就介绍几个代理方法. / 此方法在scrollView滑动时会被调用多次,只要scrollView.contentOffset发生改变就会被调用 / (void)scrollViewDidScroll:(UI

UITableView的常用属性和代理方法

以下是近期总结的关于tableView的一些属性和代理方法,以及一些常见的问题,现汇总如下,今后还会持续更新,请继续关注: tableView 的头部和尾部视图属性: UISwitch *footerView = [UISwitch new]; UISwitch *headerView = [UISwitch new]; self.tableView.tableHeaderView = headerView; self.tableView.tableFooterView = footerView

UITableView的全部属性、方法以及代理方法执行顺序,看过之后肯定有收获---董鑫

UITableView-------表视图--继承UIScrollView并遵守NSCoding协议 属性 frame-------------设置控件的位置和大小 backgroundColor--------设置控件的颜色 style--------获取表视图的样式 dataSource---------设置UITableViewDataSource的代理 delegate---------设置UITableViewDelegate代理 sectionHeaderHeight------设置