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
1.这里只记录一些学习笔记
2.这里只记录一些学习心得,如果心得方向有错,请留言
2.这里只记录一些日记(只为提升英语,暂时有点忙,等转行了开始写)