码迷,mamicode.com
首页 > 其他好文 > 详细

UITableView

时间:2015-08-05 21:42:13      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

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;
}
View Code

 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];
    }
View Code

 

UITableView

标签:

原文地址:http://www.cnblogs.com/iOS-Code/p/4700891.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!