歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> iOS中自定義Table View Cell

iOS中自定義Table View Cell

日期:2017/3/1 9:58:52   编辑:Linux編程

跟著書上的范例做完了一般的table view,然後做做自定義表格,也遇到一些問題,最後終於解決了,記錄下怎麼弄出來的吧。

知識點:

1.自定義表格cell的格式。

2.自定義表格cell的view類。

3.使用自定義的view來呈現數據。

一、自定義表格cell的格式

新建xib文件,拖table view cell,label,image view到畫板上,如圖:

二、自定義表格cell的view類

新建objective-c class,繼承UITableViewCell類,見代碼:

//
// SimpleTableViewCellController.h
// SimpleTableStoryBoradTest
//
// Created by wong linwei on 12-9-8.
// Copyright (c) 2012年 P&T. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SimpleTableViewCell : UITableViewCell {
UIImageView *cellImage;
UILabel *cellName;
UILabel *cellTime;
}

@property (strong, nonatomic) IBOutlet UIImageView *cellImage;
@property (strong, nonatomic) IBOutlet UILabel *cellName;
@property (strong, nonatomic) IBOutlet UILabel *cellTime;

@end

//
// SimpleTableViewCellController.m
// SimpleTableStoryBoradTest
//
// Created by wong linwei on 12-9-8.
// Copyright (c) 2012年 P&T. All rights reserved.
//

#import "SimpleTableViewCell.h"

@implementation SimpleTableViewCell

@synthesize cellImage;
@synthesize cellName;
@synthesize cellTime;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}
@end

Copyright © Linux教程網 All Rights Reserved