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)
这是这个系列的第二篇.在第二篇里,我决定讲一讲封装. 程序的不同部分应该用封装去互相隔离,模块之间应该不应该产生很随意的关联. 可能有的人觉得不解,又或觉得是有道理的废话,不急,先一步一步来. 我们先 ...
随机推荐
- react-native 运行提示红屏 error: bundling failed: ambiguous resolution: module `/User/xxx/Project/ico/index.js` tries to require `react-native`, but there are several files providing this module. You can de
运行 react-native start 报错 执行这2个进行清除缓存问题 yarn start -- --reset-cache npm start -- --reset-cache
- 关于iptables允许samba的问题
今天同事跟我说他们部门的共享不能用了,想了想,最近变更的只有iptables,于是看看是否是这个原因,发现没有允许samba的入站和出站规则,我的iptables规则默认是所有都drop的,但是不知确 ...
- 大浪淘沙,JSP终将死去
首先讲明,我不是标题党. 这纯属我个人的意见.勿喷. 先来讲讲JSP是怎么出现的吧. 在早期的WEB中,JS.CSS远未成熟,技术慷慨向并不明白!因为前端语言的匮乏.各家大公司都推出基于后端的模板语言 ...
- 【JS】怎样用原生JS实现jQuery的ready方法
Jquery中$(document).ready()的作用类似于传统JavaScript中的window.onload方法,只是与window.onload方法还是有差别的. 总的来说,window. ...
- ubuntu 非长期支持版升级系统版本号(ssh登录情况适用)
(1)当前系统为非长期支持版.而且已被废弃,仅仅能逐版本号升级 以当前系统版本号为11.10为例 改动source.list更新源为通用old源,由于原来的源已经不可用 deb http://old- ...
- zzulioj--1787--生活危机(vector+dfs 好题)
1787: 生化危机 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 97 Solved: 29 SubmitStatusWeb Board Desc ...
- rest_framework(解析器 上)
rest_framework 解析器 对请求题数据进行解析 url from django.conf.urls import url,include from cmdb import views ur ...
- [POJ2728] Desert King 解题报告(最优比率生成树)
题目描述: David the Great has just become the king of a desert country. To win the respect of his people ...
- POJ 1631 nlogn求LIS
方法一: 二分 我们可以知道 最长上升子序列的 最后一个数的值是随序列的长度而递增的 (呃呃呃 意会意会) 然后我们就可以二分找值了(并更新) //By SiriusRen #include < ...
- error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead解决方案
vs2012使用c语言函数fopen操作文件时报错: 错误 1 error C4996: 'fopen': This function or variable may be unsafe. Consi ...