protocol在ios中的应用
来源:互联网 发布:方天画戟淘宝 编辑:程序博客网 时间:2024/05/17 03:36
// AppDelegate.h
// Protocol_demo
//
// Created by qianfeng on 13-5-23.
// Copyright (c) 2013qianfeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@class RootViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// Protocol_demo
//
// Created by qianfeng on 13-5-23.
// Copyright (c) 2013骞?qianfeng. All rights reserved.
//
#import "AppDelegate.h"
#import "RootViewController.h"
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
//
// ViewController.h
// Protocol_demo
//
// Created by qianfeng on 13-5-23.
// Copyright (c) 2013骞?qianfeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "SettingViewController.h"
@interface RootViewController : UIViewController<SetFontSizeProtocol>
@property (nonatomic, retain) IBOutlet UILabel *label;
- (IBAction)goToSetting:(id)sender;
@end
//
// ViewController.m
// Protocol_demo
//
// Created by qianfeng on 13-5-23.
// Copyright (c) 2013骞?qianfeng. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)goToSetting:(id)sender
{
SettingViewController *settingViewController = [[SettingViewController alloc]init];
settingViewController.delegate = self;
/**
协议三部曲
1、遵循协议
2、实现方法
3、设置代理,(设置代理是为了能在发出通知的对象中,通过delegate调用实现了的协议方法)
*/
settingViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:settingViewController animated:YES completion:NULL];
[settingViewController release];
}
- (void)changeFontSize:(float)size
{
_label.font = [UIFont systemFontOfSize:size];
}
@end
//
// SettingViewController.h
// Protocol_demo
//
// Created by qianfeng on 13-5-23.
// Copyright (c) 2013骞?qianfeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@protocol SetFontSizeProtocol <NSObject>
- (void)changeFontSize:(float)size;
@end
@interface SettingViewController : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *demoLabe;
@property (assign, nonatomic) id<SetFontSizeProtocol> delegate;
- (IBAction)setFontSize:(UISlider *)sender;
@end
//
// SettingViewController.m
// Protocol_demo
//
// Created by qianfeng on 13-5-23.
// Copyright (c) 2013骞?qianfeng. All rights reserved.
//
#import "SettingViewController.h"
@interface SettingViewController ()
@end
@implementation SettingViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UINavigationBar *navigationBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
[navigationBar setBarStyle:UIBarStyleBlackTranslucent];
UINavigationItem *navigationItem = [[UINavigationItem alloc]initWithTitle:@"Setting"];
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(goBack)];
navigationItem.leftBarButtonItem = backBarButton;
[backBarButton release];
[navigationBar pushNavigationItem:navigationItem animated:NO];
[navigationItem release];
[self.view addSubview:navigationBar];
}
- (void)goBack
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)setFontSize:(UISlider *)sender {
float size = sender.value;
_demoLabe.font = [UIFont systemFontOfSize:size];
[self.delegate changeFontSize:size];
}
- (void)dealloc {
[_demoLabe release];
[super dealloc];
}
@end
- protocol在ios中的应用
- Protocol Buffer在Java中的应用
- Protocol Buffers 在游戏中的应用
- iOS中的Protocol
- 【Protobuf】Protocol buffer在Java语言中的应用01
- XMPP在iOS中的应用
- socket在ios中的应用
- OpenGL在IOS中的应用
- Nuance在iOS中的应用
- 奔五的人学IOS:Swift中的protocol及其应用实例
- Protocol buffer序列化及其在微信蓝牙协议中的应用
- Protocol buffer序列化及其在微信蓝牙协议中的应用
- Protocol buffer序列化及其在微信蓝牙协议中的应用
- Urban Airship在iOS中的应用
- Urban Airship在iOS中的应用
- Urban Airship在iOS中的应用
- MVC模式在IOS开发中的应用
- 类簇在iOS开发中的应用
- 开心水族箱
- 书评《数据挖掘技术》
- 百度地图之路径规划
- linux 中禁止普通用户关机权限
- 乐观复制算法
- protocol在ios中的应用
- 半年反思
- DirectX 3D_实践之DirectX3D的基本绘制流程
- 从头开始编译 PHP 5.5
- 乐观复制算法-1.介绍
- 中文分词评测方法
- 乐观复制算法-2.采用乐观复制技术的应用
- poj 1019
- rtcp rtp by rtsp open on ffmpeg