码迷,mamicode.com
首页 > 其他好文 > 详细

UITableView

时间:2015-11-07 13:28:16      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

 

    // 初始化VIEW

    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];

    tableView.dataSource = self;

    tableView.delegate = self;

    [self.view addSubview:tableView];

 

// ****************实现委托   <UITableViewDataSource, UITableViewDelegate>

 

 

// 总数

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

{

    return _dataArra.count;

}

 

// 获取元素cell view

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

{

    int indexPosition = indexPath.row;

    

    Person *person = [_dataArra objectAtIndex:indexPosition];

    

    //

    static NSString *identifyString = @"mytableview";

    

    UITableViewCell *cellView = [tableView dequeueReusableCellWithIdentifier:identifyString];

    

    if(!cellView)

    {

        cellView = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifyString];

    }

    cellView.textLabel.text = person.name;

    cellView.detailTextLabel.text = person.telPhone;

    

    return cellView;

}

 

// 行高

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 50;

}

 

// 点击事件响应

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    int index = indexPath.row;

    Person *person = [_dataArra objectAtIndex:index];

    

    NSLog(@"person name is : %@", person.name);

}

 

UITableView

标签:

原文地址:http://www.cnblogs.com/xiangjune/p/4944798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!