---
title: "UITableView自定义cell"
author: "刺骨的夜"
date: "2015-01-12T16:28:34Z"
tags: []
categories: ["编程语言"]
slug: "uitableview-cell"
draft: false
lastmod: "2015-01-12T16:28:34Z"
id: 2175091
url: "https://lanxs.iteye.com/blog/2175091"
---

\- (void)viewDidLoad

{

    \[super viewDidLoad];

   

    UITableView \*tableView = \[\[UITableView alloc] init];

    tableView.frame = CGRectMake(0, 0, 320, 480);

    tableView.delegate = self;

    tableView.dataSource = self;

    tableView.tableFooterView = \[\[UIView alloc] init];

    \[self.view addSubview:tableView];

 

}

 

//设置表格行数

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

    return 3;

}

//设置区数

-(NSInteger)numberOfSectionsInTableView:(UITableView \*)tableView{

    return 1;

}

//设置行高

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

    return 44;

}

//表格cell加载方法

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

    

    static NSString \*cellindentifier = @"ListCell";

   ListCell \*cell = \[tableView dequeueReusableCellWithIdentifier:@"ListCell"];

    if (cell == nil) {

          cell = \[\[\[NSBundle mainBundle] loadNibNamed:@"ListCell" owner:self options:nil] firstObject];

      }

     cell.selectionStyle = UITableViewCellSelectionStyleNone;

   

    return cell;

}

 

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

{

   \[tableView deselectRowAtIndexPath:indexPath animated:YES];

 

}