IOS的delegate 设计模式,用法及利于其编写列表 UITableView(具体编写)

5 篇文章 0 订阅
1 篇文章 0 订阅

delegate 设计模式,用法及利于其编写列表 UITableView(具体编写)

在这里插入图片描述

在app中必须用到的设计模式,也是最常用的

在这里插入图片描述
UITanView 视图 展示,协助管理,不管数据。
在这里插入图片描述
简单列表编写


    self.view.backgroundColor = [UIColor grayColor];
    UITableView *uiTabView = [[UITableView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:uiTabView];

在这里插入图片描述
引入datasurces
@interface ViewController ()``
在这里插入图片描述
实现tabview的两个方法

//cell的数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
//cell的样式 布局  数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *uiTabCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"name"];
    uiTabCell.detailTextLabel.text = @"副标题";
    uiTabCell.textLabel.text =  @"主标题";
    uiTabCell.imageView. image = [UIImage imageNamed:@"tab_purchasing_selector.png"];
    return uiTabCell;
}

在这里插入图片描述

在这里插入图片描述
运行即可:
在这里插入图片描述
简单列表 到此结束。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值