ios-表视图-demo1

时间:2014-04-28 06:09:42   收藏:0   阅读:678
bubuko.com,布布扣
//
//  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
 
bubuko.com,布布扣

 

ios-表视图-demo1,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!