您的位置:首页 > 移动开发 > IOS开发

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

}

//右划删除(系统的,加特技的自己写)

/*

- (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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: