UITableView UITableDataSource UITableViewDelegate的基本方法和属性

1.1 UITableView的基本方法和属性

  选中的行号

- (NSIndexPath *)indexPathForSelectedRow;                                                // returns nil or index path representing section and row of selection.

 表格编辑模式设置

// Editing. When set, rows show insert/delete/reorder controls based on data source queries

@property (nonatomic, getter=isEditing) BOOL editing;                             // default is NO. setting is not animated.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

 表格cell的分割线设置,但是一般不符合我们的要求

@property (nonatomic) UITableViewCellSeparatorStyle separatorStyle; // default is UITableViewCellSeparatorStyleSingleLine

1.2 UITableDataSource的基本方法和属性

  表格显示数据的三个方法

@required

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

// Row display. Implementers should *always* try to reuse cells by setting each cell‘s reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

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

@optional

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;              // Default is 1 if not implemented

  显示表格组标题

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

  表格组标题索引

// Index

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;                                                    // return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;  // tell table which section corresponds to section title/index (e.g. "B",1))

  表格自带的删除、添加,详细见UITableViewCell的滑动删除随笔

// Data manipulation - insert and delete support

// After a row has the minus or plus button invoked (based on the UITableViewCellEditingStyle for the cell), the dataSource must commit the change
// Not called for edit actions using UITableViewRowAction - the action‘s handler will be invoked instead
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

1.3 UITableViewDelegate方法

  实现自定义组头和组尾视图,需实现下面2个方法,返回的UIView为自定义View并需要继承UITableViewHeaderFooterView

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;   // custom view for header. will be adjusted to default or specified header height
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;   // custom view for footer. will be adjusted to default or specified footer height

  设置行高,组高

// Variable height support

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

  行选中方法

// Selection

// -tableView:shouldHighlightRowAtIndexPath: is called when a touch comes down on a row.
// Returning NO to that message halts the selection process and does not cause the currently selected row to lose its selected look while the touch is down.
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);

// Called before the user changes the selection. Return a new indexPath, or nil, to change the proposed selection.
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);

 行编辑

// Editing

// Allows customization of the editingStyle for a particular cell located at ‘indexPath‘. If not implemented, all editable cells will have UITableViewCellEditingStyleDelete set for them when the table has editing property set to YES.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0); // supercedes -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: if return value is non-nil

// Controls whether the background is indented while editing.  If not implemented, the default is YES.  This is unrelated to the indentation level below.  This method only applies to grouped style table views.
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;

// The willBegin/didEnd methods are called whenever the ‘editing‘ property is automatically changed by the table (allowing insert/delete/move). This is done by a swipe activating a single row
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;
时间: 2024-08-09 16:38:01

UITableView UITableDataSource UITableViewDelegate的基本方法和属性的相关文章

iOS开发 UITableView的方法和属性总结

本文描述UITableView的各种方法,属性,委托以及数据源.本文的目的只是总结UITableView的用法,详细的例子另撰文描述. 1 数据源  UITableViewDataSource协议 01 返回组(节)的个数,默认是返回1,如果只有1组数据,可以不用实现该方法. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 02 返回某一组的行数,该组由section的值决定 - (NSInteger)table

UI细节点滴-UIScorllView和UITableView/UITextView拖动退出键盘方法

在实际开发中,我们常常会用到UIScrollView以及它的子类控件UITableView/UITextView来进行某些操作需要唤出键盘.通常调出键盘的方式是使相应的控件成为事件的第一响应者,例如在一个视图加载完成后的ViewDidLoad方法中,调出键盘: - (void)viewDidAppear:(BOOL)animated {   [super viewDidAppear:animated];   [self.textView becomeFirstResponder];    //

BOM的节点方法和属性

一.HTML DOM >>>>>>>>>>>>>>>>>>>>具体可以参考W3SCHOOL中的讲解,接下来我会结合W3SCHOOL和本人总结的一些实例供大家理解. HTML 的标准对象模型 HTML 的标准编程接口 W3C 标准 HTML DOM 定义了所有 HTML 元素的对象和属性,以及访问它们的方法. 换言之,HTML DOM 是关于如何获取.修改.添加或删除 HTML 元素的标准

Python基础教程(第九章 魔法方法、属性和迭代器)

本文内容全部出自<Python基础教程>第二版,在此分享自己的学习之路. ______欢迎转载:http://www.cnblogs.com/Marlowes/p/5437223.html______ Created on Marlowes 在Python中,有的名称会在前面和后面都加上两个下划线,这种写法很特别.前面几章中已经出现过一些这样的名称(如__future__),这种拼写表示名字有特殊含义,所以绝不要在自己的程序中使用这样的名字.在Python中,由这些名字组成的集合所包含的方法称

java反射-反射实例化对象-反射获得构造方法-反射获得普通方法-获得属性

链接:https://www.zhihu.com/question/24304289/answer/38218810来源:知乎著作权归作者所有,转载请联系作者获得授权. Class<?> cls = Class.forName("cn.mldn.demo.Person"); // 取得Class对象 第一步:获得对象,构造方法,普通方法,属性 Object obj = cls.newInstance() Constructor<?> cons = cls.get

Python面向对象高级编程:@property--把方法变为属性

为了限制score的范围,可以通过一个set_score()方法来设置成绩,再通过一个get_score()来获取成绩,这样,在set_score()方法里,就可以检查参数: 1 >>> class Student(object): 2 def get_score(self): 3 return self.__score 4 def set_score(self,value): 5 if not isinstance(value,int): 6 raise ValueError('sec

java中常用的包、类、以及包中常用的类、方法、属性-----io包

由于最近有需要,所以下面是我整理的在开发中常用的包.类.以及包中常用的类.方法.属性:有需要的看看 java中常用的包.类.以及包中常用的类.方法.属性 常用的包 java.io.*; java.util.*; java.lang.*; java.math.*; java.sql.*; java.text.*; java.awt.*; javax.swing.*;   包名 接口 类 方法 属性 java.io.*; java.io.Serializable实现序列化 java.io.Buffe

ie8 报错:意外地调用了方法或属性访问

在某场景中一句简单的js: $("#changeOption").text("增加"); 在 IE8 下面报错:'意外地调用了方法或属性访问' 改成:$("#changeOption").html("增加"); 报同样的错. 改成:document.getElementById('changeOption').innerText="增加"; 同样报错:"未知的运行时错误" 最后改成:$(

C#变量初始化问题:字段初始值无法引用非静态字段、方法或属性

http://www.cnblogs.com/bluestorm/p/3432190.html 问题:字段初始值设定项无法引用非静态字段.方法或属性的问题 下面代码出错的原因,在类中定义的字段为什么不能用? public class Test {public Test(){}public int Age=23;public int temp = Age;//ERROR 字段初始值设定项无法引用非静态字段.方法或属性} C#规定在类内部只能定义属性或者变量,并初始化,不能直接变量引用变量. 在初始