1、UITableview的使用ui
UITableViewDataSource @requiredatom
1.多少组数据:spa
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;code
2.多少行数据orm
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 继承
3.设置cell的每组每行it
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
io
二、经过代码方式自定义celltable
(1)新建⼀一个继承自UITableViewCell的类class
(2)重写initWithStyle:reuseIdentifier:方法
MessageCell.h
#import <UIKit/UIKit.h> @interface MessageCell : UITableViewCell @property (retain, nonatomic) UIImageView *headImageView; @end
MessageCell.m
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor colorWithHex:0xefefef]; UIView *ticketKuang = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWith, cellHeight)]; [self.contentView addSubview:ticketKuang]; ticketKuang.backgroundColor = [UIColor whiteColor]; //选择按钮 selectBtn = [[UIButton alloc]initWithFrame:CGRectMake(-44, 5, 44, 44)]; [selectBtn setImage:[UIImage imageNamed:@"icon_list_selectBox_normal"] forState:UIControlStateNormal]; [selectBtn setImageEdgeInsets:UIEdgeInsetsMake(12, 12, 12, 12)]; //{top, left, bottom, right} [ticketKuang addSubview:selectBtn]; return self; } }
/****使用系统或者自定义cell*****/ // static NSString *cellIdentify =@"cellIdentify"; // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify]; // if(cell == nil) // { UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; cell.selectionStyle = UITableViewCellSelectionStyleNone; // }