UITableView
1.代理
UITableViewDelegate,UITableViewDataSource
2.实现代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; //分区数,默认为1 } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [data count]; //行数 } //当TableView绘制某一行的时候,会调用tableView:cellForRowAtIndexPath函数,NSIndexPath通过index.section和index.Row可以获取到当前行分区的下标和行下标 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellTableIndetifier=@"CellTableIdentifier"; //在缓存里面找cell,如果没有则重新创建 UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellTableIndetifier]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellTableIndetifier]; } //系统自带 // cell.detailTextLabel //cell.imageView cell.textLabel.text=[data objectAtIndex:indexPath.row]; return cell; }
3.自定义Cell,Nib中加载
static NSString *indentity=@"CustomCell"; CustomTableViewCell *cell=(CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:indentity]; if (cell==nil) { NSArray *boundle=[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil]; cell= [boundle objectAtIndex:0]; }