iOS tableView的用法
- (void)viewDidLoad
{
[superviewDidLoad];
UITableView*myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,Screen_width,Screen_height)style:UITableViewStylePlain];
// UITableViewStyleGrouped分组
myTableView.dataSource=self;
myTableView.delegate=self;
[selfcancelCell:myTableView];
[self.viewaddSubview:myTableView];
// Do any additional setup after loading the view,;typically from a nib.
}
#pragma mark-once行数
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return3;
}
#pragma mark-once行内容
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
staticNSString*cellID =@"cellID";
UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:cellID];
if(cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
//UITableViewCellStyle 是个枚举
//UITableViewCellStyleDefault;默认的
//UITableViewCellStyleSubtitle;
//UITableViewCellStyleValue1;
//UITableViewCellStyleValue2;
cell.textLabel.text= [NSString stringWithFormat:@"%ld",(long)indexPath.row];
//给右边加个标识符的
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
//选中的颜色
cell.selectionStyle=UITableViewCellSelectionStyleBlue;
returncell;
}
#pragma mark-once几组
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView;
{
return2;
}
#pragma mark-once头标题
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
{
return@"第一个标题";
}
#pragma mark-once未标题
- (NSString*)tableView:(UITableView*)tableView titleForFooterInSection:(NSInteger)section
{
return@"最后一个标题";
}
#pragma mark-once标识符accessoryButtonTappedForRow方法
- (void)tableView:(UITableView*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath
{
}
#pragma mark-once类似电话那种最右边的a,b,c,d,e-z
- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView
{
NSArray*rightArry = @[@"A",@"B",@"c",@"d",@"e",@"f",@"g"];
returnrightArry;
}
#pragma mark-once行高
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
return50;
}
#pragma mark-once头标题的高度
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
return50;
}
#pragma mark-once未标题的高度
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return50;
}
#pragma mark-once行高
-(void)cancelCell:(UITableView*)tableView
{
UIView*view = [UIViewnew];
view.backgroundColor= [UIColor clearColor];
[tableViewsetTableFooterView:view];
view.frame=CGRectMake(0, 0, tableView.frame.size.width, 20);
}
#pragma mark-once选中的方法
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSLog(@"%ld",(NSInteger)indexPath.row);
}
#pragma mark-once编辑的方法
- (BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath
{
return YES;
}
#pragma mark-once是否允许移动
- (BOOL)tableView:(UITableView*)tableView canMoveRowAtIndexPath:(NSIndexPath*)indexPath
{
return YES;
}
#pragma mark-once编辑的方法
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
{
}
#pragma mark-once移动的方法
- (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath
{
}
#pragma mark-once分割线
-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath{
if([tableViewrespondsToSelector:@selector(setSeparatorInset:)]) {
[tableViewsetSeparatorInset:UIEdgeInsetsZero];
}
if([tableViewrespondsToSelector:@selector(setLayoutMargins:)]) {
[tableViewsetLayoutMargins:UIEdgeInsetsZero];
}
if([cellrespondsToSelector:@selector(setLayoutMargins:)]) {
[cellsetLayoutMargins:UIEdgeInsetsZero];
}
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。