iOS开发之tableView(自用贴)
2015-11-11 14:32
337 查看
//声明:本贴为自用贴,介于本人使用习惯可能不大家的使用习惯不同,不喜勿喷。
//经常用(这些基本够用除非要加特技)
<UITableViewDataSource,UITableViewDelegate>//两个代理
UITableView*table=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
table.delegate=self;
table.dataSource=self;
[self.view addSubview:table];
#pragma mark 代理 //常用的四个代理
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;//一行section中cell的个数 不写,即默认为1
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;//cell的高度
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellStr=@"todayCell";//本人习惯用xib
tadayDataTableViewCell *cell = (tadayDataTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellStr];
if(cell ==nil) {
NSArray *nibArray = [[NSBundle mainBundle]loadNibNamed:@"tadayDataTableViewCell" owner:self options:nil];
cell = (tadayDataTableViewCell *)[nibArray objectAtIndex:0];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;//去除点击效果
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"点击了cell");
}
//刷新table
[table reloadData];
//可能用(小特技)
table.separatorStyle=UITableViewCellSeparatorStyleNone;//去除cell多余的分割线
table.scrollEnabled=NO;//table的滚动效果
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;//section的个数 不写,即默认为1
}
//右划删除(系统的,加特技的自己写)
/*
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//删除处理
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"删除";
}
*/
//消除cell选择痕迹
/*
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
}
- (void)deselect
{
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:NO];
}
*/
//不常用
//section里的文字
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
//section头的高度,可以写一些自己想要的section头(有悬浮效果,当然悬浮效果可以关)
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//section头的view
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
//section底的高度
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
//section底的view
}
//经常用(这些基本够用除非要加特技)
<UITableViewDataSource,UITableViewDelegate>//两个代理
UITableView*table=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
table.delegate=self;
table.dataSource=self;
[self.view addSubview:table];
#pragma mark 代理 //常用的四个代理
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;//一行section中cell的个数 不写,即默认为1
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;//cell的高度
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellStr=@"todayCell";//本人习惯用xib
tadayDataTableViewCell *cell = (tadayDataTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellStr];
if(cell ==nil) {
NSArray *nibArray = [[NSBundle mainBundle]loadNibNamed:@"tadayDataTableViewCell" owner:self options:nil];
cell = (tadayDataTableViewCell *)[nibArray objectAtIndex:0];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;//去除点击效果
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"点击了cell");
}
//刷新table
[table reloadData];
//可能用(小特技)
table.separatorStyle=UITableViewCellSeparatorStyleNone;//去除cell多余的分割线
table.scrollEnabled=NO;//table的滚动效果
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;//section的个数 不写,即默认为1
}
//右划删除(系统的,加特技的自己写)
/*
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { }
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//删除处理
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"删除";
}
*/
//消除cell选择痕迹
/*
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
}
- (void)deselect
{
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:NO];
}
*/
//不常用
//section里的文字
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return @""; }
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
//section头的高度,可以写一些自己想要的section头(有悬浮效果,当然悬浮效果可以关)
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//section头的view
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
//section底的高度
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
//section底的view
}
相关文章推荐
- iOS KVO 常见错误
- iOS中对文件的操作 NSSearchPathForDirectoriesInDomains
- iOS 获取本地视频播放路径
- iOS开发之音频
- IOS 在一个应用里打开另一个应用 及其 两个应用互相调用
- iOS JSON 和 Mode l转换
- iOS_清除xcode编译器的缓存
- iOS NSDate NSCanlendar NSComponent 概念讲解
- IOS 中block结构的简单用法
- iOS 消除对应的警告!
- iOS执行多线程的方法
- IOS--NSString(字符串截取)
- 磁盘性能检测iostat
- iOS 读取本地Json文件
- iOS keyChain 研究
- 系统升级到iOS9,真机运行报“was compiled with optimization - stepping may behave oddly...”,闪退
- iOS开发:货币的精确计算
- iOS-网页调用百度地图API
- iOS开发中常用的宏
- iOS之图片处理