本博客讲的是使用xib自定义tableViewcell

1、创建一个工程,选择single View,然后next

并命名为CustomTableView

2、我们自定义一个xib文件,并在里面实现我们需要的cell

2.1 新建一个xib

选择user Interface ,然后我们选择Empty(这里选择空的是为了方便在后面的xib里面放自定义大小的cell,也可以选择View)

然后默认就可以

然后就是命名了,这里命名为customCell

3.1放一个tableView cell到这个xib中,直接拖过来就可

            

然后设置cell的宽度和高度。

3.2往cell里放一个imageview和两个label

3.3关联这个xib属于哪个类

然后回车

选择imageview右键弹出referencing outlets,然后拖一根线到.h文件并命名为cellImageview,同理label也是,然后得到下图所示

12,13,14前面有小圆黑点表示属性关联上了

4.1、创建一个tableView

#import "FookeViewController.h"
@interface FookeViewController ()<UITableViewDelegate,UITableViewDataSource>    //引入代理
@end
@implementation FookeViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //创建一个customView,并设置它的类型为:UITableViewStylePlain
    UITableView *customView = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, 320, 480-44) style:UITableViewStylePlain];
    //实现代理和数据源方法
    customView.delegate = self;
    customView.dataSource = self;
    //添加到self.view 上
    [self.view addSubview:customView];
}

4.2然后我们给它加上我们需要的数据

@interface FookeViewController ()<UITableViewDelegate,UITableViewDataSource>    //引入代理
{
    NSArray *titleArr,*imageArr,*introductionArr;//创建3个数组,分别显示标题,图像,简介
}
@end

在- (void)viewDidLoad里面添加代码(向工程中添加入图片名为12345的5张png图)

4.3 实现它的代理方法和数据源方法(其中必须实现的一定要实现)

运行查看效果

这就是通过xib实现自定义类似新闻列表的tableViewcell

 

posted on 2014-08-09 02:04  fooke  阅读(221)  评论(0编辑  收藏  举报