iOS UI 07 uitableviewi2

//

//  RootViewController.m

//  UI - 08 UItableview

//

//  Created by dllo on 15/11/18.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "RootViewController.h"


@interface RootViewController () <UITableViewDelegate, UITableViewDataSource>


@end


@implementation RootViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    

    

    UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];

    table.delegate = self;

    table.dataSource = self ;

    [self.view addSubview:table];

    [table release];

    

    

    

    UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 100)] autorelease];

    view.backgroundColor = [UIColor greenColor];

    table.tableHeaderView = view;

    

    

    

    

    

    

    // Do any additional setup after loading the view.

}

//行数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return 5;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    

    //static ,只在编译的时候执行一次,以后不再执行

   static NSString *cellStr = @"cell";

//    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle: UITableViewCellStyleDefault reuseIdentifier:cellStr];

//    NSLog(@"%d", __LINE__);

    

    //到重用池中取cell, 若有直接用,若无创建新的cell

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];

    if (nil == cell) {

        cell = [[[UITableViewCell alloc] initWithStyle:    UITableViewCellStyleValue1 reuseIdentifier:cellStr] autorelease];

        cell.textLabel.text = @"泰勒-斯威夫特";

        cell.imageView.image = [UIImage imageNamed:@"1.png"];

        cell.detailTextLabel.text = @"

posted @ 2015-12-13 16:03  挽月细数风流  阅读(92)  评论(0编辑  收藏  举报