ios-表视图-demo1
// // RootViewController.m // uitableview // // Created by liyang on 14-4-27. // Copyright (c) 2014年 liyang. All rights reserved. // #import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(void)loadView{ UIView *view=[[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]]; self.view=view; _uitableview=[[UITableView alloc]initWithFrame:view.bounds style:UITableViewStylePlain]; _uitableview.dataSource=self;//设置数据源代理 _uitableview.rowHeight=45;//行高,默认的44 UIImageView*imageview= [[UIImageView alloc]initWithFrame:self.view.bounds]; imageview.image=[UIImage imageNamed:@"IMG_0410"];//设置背景图片 _uitableview.backgroundView=imageview; _fontarry=[UIFont familyNames]; //设置表视图的分割线 //_uitableview.separatorColor=[UIColor grayColor]; //_uitableview.separatorStyle=UITableViewCellSeparatorStyleNone; //设置头部视图(上面加上各种子视图) UIView* headerview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)]; headerview.backgroundColor=[UIColor purpleColor]; _uitableview.tableHeaderView=headerview; //设置尾部视图(上面加上各种子视图) UIView* footerview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)]; footerview.backgroundColor=[UIColor yellowColor]; _uitableview.tableFooterView=footerview; [self.view addSubview:_uitableview]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [_fontarry count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *cellindentifier=@"cellidentifier"; UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:cellindentifier]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellindentifier]; } NSString *fontname=_fontarry[indexPath.row]; NSLog(@"%d",indexPath.row); cell.textLabel.text=fontname; cell.textLabel.font=[UIFont fontWithName:fontname size:14]; return cell; } //页眉这2个和后面的自定义是相互冲突的,两者取其一 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return @"liyangstart"; } //页脚 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{ return @"liyangend"; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。