iOS中自定义Table View Cell

跟着书上的范例做完了一般的table view,然后做做自定义表格,也遇到一些问题,最后终于解决了,记录下怎么弄出来的吧。

知识点:

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

2.自定义表格cell的view类。

3.使用自定义的view来呈现数据。

一、自定义表格cell的格式

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

iOS中自定义Table View Cell

二、自定义表格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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b6aaaa81a024f521e9f6b8c43ff140e3.html