0
点赞
收藏
分享

微信扫一扫

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


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

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

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

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


UITanView 视图 展示,协助管理,不管数据。

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


简单列表编写

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

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


引入datasurces

@interface ViewController ()``

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


实现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;
}

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

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


运行即可:

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


简单列表 到此结束。


举报

相关推荐

0 条评论