IOS-MVC设计模式深入
来源:互联网 发布:云计算能力开放全景图 编辑:程序博客网 时间:2024/05/21 17:36
大家都知道我们开发采用MVC设计模式,但是又有多少人从项目从头到尾一直使用MVC呢。
下面说一下我们如何使用MVC和基础
如果我们有一个要求: 一个页面 有2个按钮 2个按钮 切换不同的数据,第一个按钮是UITableview 第二个是UIScrollview 那么我们应该如何应用在这个页面呢?
2种方法 :
1.我们可以给2个按钮设置不同tag值 进行页面切换 并且切换时隐藏。
//详细说一下第二种方法 必要时 附上代码 .
2.我们创建一个基础VC 用于协调这2个UI控件的VC.
基础VC 只是用于切换视图,这样我们tableView 和scrollview 2个VC 写好 控制器,并且 写好自定义cell 和 scrollview所需要的UI界面。
在2个VC中 创建 UI界面的 实例对象 ,并且执行 方法 我们可以使用代理 代理到基础VC执行 。
#import "MYBrandHeaderView.h"
#import "MYBrandHeaderDelegate.h"
@protocol MYBrandTableViewControllerDelegate <NSObject>
- (void)showBrandProduct:(NSDictionary *)dict;
- (void)showGroup:(NSDictionary *)dict;
@end
@interface MYBrandTableViewController :BaseViewController
@property (nonatomic,strong) UITableView *circleTableView;
@property (nonatomic,strong) MYBrandHeaderView *headerView;
@property (nonatomic,assign)id<MYBrandTableViewControllerDelegate> delegate;
- (instancetype)initWithBrandID:(NSString *)brandID;
//我这里只有一个代理方法 用于显示数据
- (void)showBrandProduct:(NSDictionary *)dict
{
if (_delegate && [_delegaterespondsToSelector:@selector(showBrandProduct:)]) {
[_delegateshowBrandProduct:dict];
}
}
- (void)showGroup:(NSDictionary *)dict
{
if (_delegate && [_delegaterespondsToSelector:@selector(showGroup:)]) {
[_delegateshowGroup:dict];
}
}
//这样 我吧tableview这个页面获取到得dict数据传入 基础VC
//在基础VC中 切换2个页面
- (void)showBrandProduct:(NSDictionary *)dict
{
if (!isProductMode) {
isProductMode = !isProductMode;
_tableViewVC.view.hidden =YES;
[selftransitionFromViewController:currentVCtoViewController:_collectionVCduration:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{
}completion:^(BOOL finished) {
_collectionVC.view.hidden =NO;
currentVC =_collectionVC;
}];
}
}
- (void)showGroup:(NSDictionary *)dict
{
if (isProductMode) {
isProductMode = !isProductMode;
_collectionVC.view.hidden =YES;
[selftransitionFromViewController:currentVCtoViewController:_tableViewVCduration:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{
}completion:^(BOOL finished) {
_tableViewVC.view.hidden =NO;
currentVC =_tableViewVC;
}];
}
}
这样就实现了 MVC 构造。UI界面 请自行创建 组合控件,如果有重复的地方可以 封装。
- IOS-MVC设计模式深入
- iOS 设计模式MVC
- iOS设计模式---MVC
- ios mvc设计模式
- iOS MVC设计模式
- iOS MVC设计模式
- iOS MVC设计模式
- IOS设计模式:MVC模式
- iOS开发设计模式-MVC
- IOS-MVC设计模式初探
- iOS-MVC设计模式
- iOS 的MVC设计模式
- iOS中的MVC设计模式
- iOS中的MVC设计模式
- iOS的MVC设计模式
- 【iOS开发】MVC设计模式
- iOS MVC设计模式详解
- iOS中的MVC设计模式
- c#面试问题
- 存储过程与函数的区别
- 未能同步iPad 因为这台电脑不再被授权使用在此iPad上购买的项目
- g++: error trying to exec 'cc1plus': execvp: 没有那个文件或目录
- 免费WiFi分享给你,全民免费WiFi来袭
- IOS-MVC设计模式深入
- 用Pix调试HLSL
- cocos2dx jni Android.mk配置,实现自动搜索.cpp文件打包
- hdu 4902 Nice Boat
- 【Twitter Storm系列】flume-ng+Kafka+Storm+HDFS 实时系统搭建
- 计算字符串的长度
- eclipse运行mapreduce报错Permission denied
- android开发 drawable中XML的相关应用
- leetcode Linked List Cycle & Linked List Cycle ||