标签:
1.基于MVC设计模式---实现低耦合,层与层之间实现独立,增强代码的复用性,充分实现M层和V层之间的独立
2.利用代理模式 实现从V层向C层传值---在C层拿到V层的数据,从而对数据本身做一些改变(操作),进而实现V层视图的改变
2.1协议实现
2.2委托实现
3.代理实现
@interface BCRootViewController ()<BCRootViewDelegate>
@property(nonatomic,retain)BCRootView *rootView;
@property(nonatomic,assign)UIView *optView;
@end
@implementation BCRootViewController
- (void)dealloc
{
[_rootView release];
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)loadView
{
self.rootView = [[BCRootView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view = self.rootView;
[_rootView release];
}
- (void)viewDidLoad
{
[super viewDidLoad];
/**
* 设置根式图的代理 为自己
*/
self.rootView.delegate = self;
/**
*
*/
self.optView = self.rootView.redView;
}
#pragma mark ---segment的点击方法
- (void)BCRootViewSegementDidClicked:(UISegmentedControl *)send
{
if (send.selectedSegmentIndex == 0) {
self.optView = self.rootView.redView;
}else{
self.optView = self.rootView.blueView;
}
}
#pragma mark ---slider的点击方法
- (void)BCRootViewSliderDidClicked:(UISlider *)redSlider :(UISlider *)greenSlider :(UISlider *)blueSlider
{
self.optView.backgroundColor = [UIColor colorWithRed:redSlider.value green:greenSlider.value blue:blueSlider.value alpha:1.0];
}
#pragma mark --- switch的点击方法
- (void)BCRootViewSwitchDidClicked:(UISwitch *)sender
{
if (sender.isOn == YES) {
self.optView.hidden = YES;
return;
}
self.optView.hidden = NO;
}
#pragma mark --- stepper的点击方法
- (void)BCRootViewStepperDidClicked:(UIStepper *)sender
{
self.optView.frame = CGRectMake(self.optView.frame.origin.x, self.optView.frame.origin.y, self.optView.frame.size.width, sender.value);
}
标签:
原文地址:http://www.cnblogs.com/bachl/p/4625569.html