`

UITableView自定义cell

 
阅读更多

 

- (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];

 

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics