一些tableView的基础Knowledge(2015414)
来源:互联网 发布:金10数据官网 双十一 编辑:程序博客网 时间:2024/05/17 02:34
1.xcode 6.2
删除原有的ViewController,添加一个tableViewController出现下面的情况。
“Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?”
需要在main.storyboard设置,设置tableViewController选中 【Is Initial View Controller】
2.比较有用的代码块
关于KVC编程,将plist中的文件抽象出来,下面的代码是初始化会用到的代码。
-(instancetype)initWithDict:(NSDictionary *)dict
{
self = [super init];
if (self) {
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+(instancetype)<#name#>WithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
+(NSArray *)<#name#>
{
NSArray *array=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"<#plist#>" ofType:nil]];
NSMutableArray *arrM=[NSMutableArray array];
for (NSDictionary *dict in array) {
[arrM addObject:[self <#name#>WithDict:dict]];
}
return arrM;
}
PS:这里的plist只是最简单类型:Array-Dictionary 若是更复杂的清苦需要嵌套。
3.关于tableView加载数据
如果是UITableViewDataSource代理实现两个方法,下面方法是其中之一,另一个easy,不多说
UITableViewDataSource(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *ID=@"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
……
}
上面这段数据可以重复使用cell,大大提高效率,过后可能更简洁的方法实现
4.打开iphone的通讯录,可以发现右侧的的字母ABCD...索引,下面这个方法就是实现这个功能。
#pragma mark tableView的右侧的索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return 【某一个数组】
}
5.常用的TableView的代理方法
#pragma mark 返回UITableViewCellEditingStyle 的类型
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
#pragma mark 视tableView能够实现拖动的效果
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
if(editingStyle==UITableViewCellEditingStyleDelete)
{
[self.tableList removeObjectAtIndex:indexPath.row];
// [self.tableView reloadData];//重新加载数据,刷新列表
//实现动态的效果
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if(editingStyle==UITableViewCellEditingStyleInsert)
{
[self.tableList insertObject:@"你好" atIndex:indexPath.row+1];
// [self.tableView reloadData];
NSIndexPath *path=[NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
[self.tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationFade];
}
}
6.像button那样的控件可以添加监听的方法,但是tableView等很多控件无法这样做,但是有了代理,这样就方便了,从这个意义上讲代理模式相当给力。
删除原有的ViewController,添加一个tableViewController出现下面的情况。
“Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?”
需要在main.storyboard设置,设置tableViewController选中 【Is Initial View Controller】
2.比较有用的代码块
关于KVC编程,将plist中的文件抽象出来,下面的代码是初始化会用到的代码。
-(instancetype)initWithDict:(NSDictionary *)dict
{
self = [super init];
if (self) {
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+(instancetype)<#name#>WithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
+(NSArray *)<#name#>
{
NSArray *array=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"<#plist#>" ofType:nil]];
NSMutableArray *arrM=[NSMutableArray array];
for (NSDictionary *dict in array) {
[arrM addObject:[self <#name#>WithDict:dict]];
}
return arrM;
}
PS:这里的plist只是最简单类型:Array-Dictionary 若是更复杂的清苦需要嵌套。
3.关于tableView加载数据
如果是UITableViewDataSource代理实现两个方法,下面方法是其中之一,另一个easy,不多说
UITableViewDataSource(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *ID=@"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
……
}
上面这段数据可以重复使用cell,大大提高效率,过后可能更简洁的方法实现
4.打开iphone的通讯录,可以发现右侧的的字母ABCD...索引,下面这个方法就是实现这个功能。
#pragma mark tableView的右侧的索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return 【某一个数组】
}
5.常用的TableView的代理方法
#pragma mark 返回UITableViewCellEditingStyle 的类型
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
#pragma mark 视tableView能够实现拖动的效果
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
if(editingStyle==UITableViewCellEditingStyleDelete)
{
[self.tableList removeObjectAtIndex:indexPath.row];
// [self.tableView reloadData];//重新加载数据,刷新列表
//实现动态的效果
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if(editingStyle==UITableViewCellEditingStyleInsert)
{
[self.tableList insertObject:@"你好" atIndex:indexPath.row+1];
// [self.tableView reloadData];
NSIndexPath *path=[NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
[self.tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationFade];
}
}
6.像button那样的控件可以添加监听的方法,但是tableView等很多控件无法这样做,但是有了代理,这样就方便了,从这个意义上讲代理模式相当给力。
0 0
- 一些tableView的基础Knowledge(2015414)
- tableView的一些函数
- tableView的一些方法
- tableview的一些使用方法
- tableView的一些细节
- tableview的一些基本知识
- tableView的一些使用
- tableView的一些坑
- 关于tableview的一些bug
- tableView的一些基本方法
- iOS---tableView的一些内容
- tableview的一些常用方法
- web.py 环境的配置以及一些basic knowledge
- little knowledge及errno的一些错误定义
- 图像处理的一些相关知识(Related knowledge for IQA)
- Python3 基础:some knowledge
- TableView的一些需要掌握的东西
- 关于tableview 的一些属性设置
- 在iOS开发中使用FMDB
- HTTP协议之消息报头
- SQL存储位置修改
- OpenCV 矩阵(图像)操作函数
- 房间安排
- 一些tableView的基础Knowledge(2015414)
- Android DrawerLayout 高仿QQ5.2双向侧滑菜单
- Combining multi-architecture binaries with lipo and libtool
- CSDN-markdown编辑器
- 杭电2535(Vote)
- android时间对话框TimePickerDialog介绍
- Hadoop编程调用HDFS
- 模仿,类比,移植技法(创新技法5)
- 如何定义和实现一个类的成员函数为回调函数