iPad popView封装
仿照UITableView的UITableViewDataSource
协义
1.代理。让代理帮我们类完毕一些方法
2.完毕当前类不能完毕的事情还有传值等功能
实现方法
// 1. 声明一个协议
// 2. 声明协议中的方法
// 3. 声明一个遵守协议的id类型的指针
// 4. 实现协议方法
@class popView;
@protocol MyPopviewDataSource <NSObject>
//制定协议方法
//left tablevie 行数
- (NSInteger)numberOfRowsInLeftTable:(popView *)popView;
//left 标题
- (NSString *)popView:(popView *)popView titleForRow:(NSInteger)row;
//left 图标
- (NSString *)popView:(popView *)popView imageForRow:(NSInteger)row;
//left 子数据
- (NSArray *)popView:(popView *)popView subDataForRow:(NSInteger)row;
@end
@interface popView :UIView
@property (nonatomic,assign)id<MyPopviewDataSource> dataSource;
+ (popView*)makePopView;
@end
#import "popView.h"
@interface popView ()<UITableViewDataSource,UITableViewDelegate>
@property (weak,
nonatomic) IBOutletUITableView *leftTV;
@property (weak,
nonatomic) IBOutletUITableView *rightTV;
@property (nonatomic,assign)NSInteger selectRow;
@end
@implementation popView
+ (popView *)makePopView
{
return [[[NSBundlemainBundle]loadNibNamed:@"popView"owner:selfoptions:nil]firstObject];
}
#pragma mark - tableview delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == _leftTV) {
return [self.dataSourcenumberOfRowsInLeftTable:self];
}else{
return [self.dataSourcepopView:selfsubDataForRow:_selectRow].count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _leftTV) {
static NSString *str =@"Mycell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
if (cell ==
nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:str];
}
cell.textLabel.text = [self.dataSourcepopView:selftitleForRow:indexPath.row];
cell.imageView.image = [UIImageimageNamed:[self.dataSourcepopView:selfimageForRow:indexPath.row]];
NSArray *subDataArray = [self.dataSourcepopView:selfsubDataForRow:indexPath.row];
if (subDataArray.count) {
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
}else{
cell.accessoryType =UITableViewCellAccessoryNone;
}
return cell;
}else{
static NSString *str =@"Mycell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
if (cell ==
nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:str];
}
cell.textLabel.text = [self.dataSourcepopView:selfsubDataForRow:_selectRow][indexPath.row];
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _leftTV) {
self.selectRow = indexPath.row;
[_rightTVreloadData];
}
}
@end
在控制器使用
#import "PopViewController.h"
#import "popView.h"
#import "CategoriyModel.h"
@interface PopViewController ()<MyPopviewDataSource>
@end
@implementation PopViewController
- (void)viewDidLoad
{
[superviewDidLoad];
popView *pop = [popViewmakePopView];
[self.viewaddSubview:pop];
pop.dataSource =self;
pop.autoresizingMask =UIViewAutoresizingNone;
self.preferredContentSize =CGSizeMake(pop.frame.size.width, pop.frame.size.height);
}
//获取到
第一个分类数据下拉菜单的模型数组
- (NSArray *)getData
{
CategoriyModel *md = [[CategoriyModelalloc]init];
NSArray *categorieyArray = [md loadPlistData];
return categorieyArray;
}
#pragma mark - popview dataSource
- (NSInteger)numberOfRowsInLeftTable:(popView *)popView{
return [selfgetData].count;
}
- (NSString *)popView:(popView *)popView titleForRow:(NSInteger)row{
return [[selfgetData][row]name];
}
- (NSString *)popView:(popView *)popView imageForRow:(NSInteger)row{
return [[selfgetData][row]small_icon];
}
- (NSArray *)popView:(popView *)popView subDataForRow:(NSInteger)row{
return [[selfgetData][row]subcategories];
}
@end
iPad popView封装的更多相关文章
- iPad编程
1. iPad 现有型号: iPad Pro, iPad Air, iPad mini 均配备Retina显示屏.早期还有iPad 依次对应的坐标系及分辨率: iPad Pro 坐标系:1366 x ...
- 功能源代码(扇形进度)及Delegate运用在开放事件中、UINavigationController的封装
1:扇形进度视图及运用 首先先创建扇形的视图,传入进度值 #import <UIKit/UIKit.h> @interface LHProgressView : UIView @prope ...
- iPad和iPhone开发区别
原文:http://mobile.51cto.com/iphone-273895.htm iPad与iPhone 开发区别详解是本文要介绍的内容,先来看看他们的区别. 1.首先我们先从官方发布的SDK ...
- 封装同步的UIActionSheet
封装同步的UIActionSheet 发问题 做 iOS 开发的同学想必都用过 UIActionSheet.UIActionSheet 可以弹出一个选择列表,让用户选择列表中的某一项操作.使用 UIA ...
- 封装cookie.js、EventUtil.js、
最近学习了javascript,封装好的东西看起来舒服,以备需要的时候拉出来,jquery对javascript做了很好的封装!以后会多用jquery多些 var CookieUtil = { get ...
- 初识iOS9 iPad新特性SlideView和SplitView的适配
苹果刚发布了iOS9,在iPad上新增了两个新的特性SlideView和SplitView,前者可以在不关闭当前激活APP的情况下调出来另外个APP以30%比例显示进行操作使用,后者允许同时运行两个A ...
- iPad开发(相对于iPhone开发时专有的API)
iPad开发 一.iPad开发简介 1.什么是iPad 一款苹果公司于2010年发布的平板电脑 定价介于苹果的智能手机iPhone和笔记本电脑产品之间 跟iPhone一样,搭载的是iOS操作系统 2. ...
- oc之封装与类之间的关系
1. 面向对象的特征-封装? 封装: 现实生活中的封装: 将很多的小东西 塞在1个大口袋里面. 好处: a. 对外部屏蔽. b. 方便管理. 代码的封装: 函数/方法 就是1种封装的体现: 将一段代码 ...
- 架构漫谈系列(2) 封装(Encapsulation)
这是这个系列的第二篇.在第二篇里,我决定讲一讲封装. 程序的不同部分应该用封装去互相隔离,模块之间应该不应该产生很随意的关联. 可能有的人觉得不解,又或觉得是有道理的废话,不急,先一步一步来. 我们先 ...
随机推荐
- Docker中免去sudo的设置方法
Add the docker group if it doesn't already exist: sudo groupadd docker Add the connected user " ...
- DIV+CSS布局中自适应高度的解决方法
div乱跑问题 (文件<DIV+CSS布局中自适应高度的解决方法.rar>) float 是个很危险的东西 得小心使用 本来有一很好的关于CSS+DIV的论坛 不过现在关门了 甚是可 ...
- 详解:(cron , crontab , anacron)
导读: 人类把时间做了切割,想象一条笔直的线永远向前,本来这条直线上什么都没有,但是人类根据时间的长短(单位)在这条直线上做了密密麻麻的标记(世纪-年-月-日-时-分-秒-纳秒......),通过这样 ...
- 关于Jwt的一些思考
在使用jwt的过程中发现了两个问题续期和退出的问题. 续期 因为jwt的token在签发之后是有过期时间的,所以就存在管理这个过期时间的问题.我看网上有提出解决方案的大致有下面几个 每次更新过期时间, ...
- java 实现顺序结构线性列表
package com.ncu.list; /** * * 顺序结构线性列表 * * @author liuhao * */ public class SquenceList<T> { p ...
- HttpClient 图讲解明
大家刚看这个名字一定会想问这是什么东东,在这我特意百度百科了下 HTTP 协议可能是如今 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序须要直接通过 HTTP 协议来訪 ...
- 设计模式-策略模式(Go语言描写叙述)
好久没有更新博客了.近期也是在忙着充电,今天这篇博客開始,我们来了解一下设计模式. 设计模式 那什么是设计模式呢?首先来看看我从百科上copy下来的概念吧. 设计模式/软件设计模式(Design pa ...
- 小米净水器与小区过滤价格水对照.xls
总结:要是一天用水量为7升下面.还是用小区的过滤水为好,合算. 假设过滤水需求量大,可能小米的净水器比較好.当然,小区的要天天去接.要求风雨无阻的. 这点小米的随用随接就更好. 注意一点,小米的还要用 ...
- hdoj--2098--分拆素数和(水题)
分拆素数和 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- Apache Bench测试
- 压力测试神器 Siege - Locust Web测压工具python开源 - 介绍: ab是apachebench命令的缩写. ab的原理:ab命令会创建多个并发访问线程,模拟多个访问者同时对某 ...