联系人列表0~100

这是一个小的知识点,做出来的效果如图所示:

虽然很简单的页面,可是初学的时候还是很纠结的没有做出来,在这里写出他的程序

第一步:

第二步:

在MangoViewController.h中遵循<UITableViewDataSource>协议

第三步:

#import "MangoViewController.h"
@interface MangoViewController ()
@property(nonatomic,retain) UITableView *tableView;
@end
@implementation MangoViewController
- (void)dealloc{
    [_tableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor cyanColor];
    //设置导航栏标题
    self.navigationItem.title = @"联系人";
    //创建一个UITableView
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    //分割线颜色
    self.tableView.separatorColor = [UIColor redColor];
    //分割线样式
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    //背景颜色
    self.tableView.backgroundColor = [UIColor yellowColor];
    //设置tableView数据源代理
    self.tableView.dataSource = self;
    //添加到当前视图
    [self.view addSubview:self.tableView];
    //释放
    [self.tableView release];
    }
//分区中有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 101;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //重用机制实现原理
    static NSString *cellIdentifier = @"CycleCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
    cell.imageView.image = [UIImage imageNamed:@"3.jpg"];
    return cell;
}
//默认分区1个
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

总结:

1.cell.imageView.image = [UIImage imageNamed:@"3.jpg"];是添加图片

2.cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];实现0~100











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值