iOS 通知的基本用法
来源:互联网 发布:阿莫源码社区 编辑:程序博客网 时间:2024/05/15 09:26
一、首先要注册通知
#import "RootViewController.h"@interface RootViewController (){ NSTimer *_timer;//添加定时器}@end@implementation RootViewController- (void)viewDidLoad { [super viewDidLoad]; //注册通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callBack) name:@"back" object:nil]; [self creatNStimer];}
启用定时器
-(void)creatNStimer{ NSLog(@"get it"); _timer=[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(Notification) userInfo:nil repeats:NO]; //发出通知}
二、执行通知
-(void)Notification{ //发出通知 [[NSNotificationCenter defaultCenter] postNotificationName:@"back" object:self];}-(void)callBack{ //执行通知 NSLog(@"this is Notification");}
三、移除通知
-(void)dealloc{ //移除通知 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"back" object:nil];}
0 0
- iOS 通知的基本用法
- iOS 通知的基本用法
- Notification通知的基本用法
- Notification--------通知的基本用法
- iOS NSNotification 通知的用法
- Android中通知的基本用法
- 系统通知Notification的基本用法
- android 通知Notification的基本用法
- 安卓通知的基本用法
- 23读书笔记之通知的基本用法
- IOS本地通知(UILocalNotification)的基本使用
- iOS 通知的基本使用传值
- 通知基本用法NSNotificationCenter
- iOS通知用法
- iOS通知用法
- iOS UILabel的基本用法
- iOS CoreData的基本用法
- ios NSNotFound的基本用法
- 解决小米手机出现INSTALL_FAILED_UID_CHANGE错误,安装应用失败的问题
- java 生成xml并转存为zip
- JQuery 中的事件命名空间
- Leetcode:Valid Sudoku
- 通过Safari浏览器获取iOS设备UDID(设备唯一标识符)
- iOS 通知的基本用法
- SVD分解和PCA
- 【面试题】:统计一串字符串中仅出现一次的第一个字符
- android的内部与外部存储目录
- Java算法题:兔子问题
- TOMCAT导入通过第三方证书机构获取的证书
- 判断有线网络连接的方式
- 002.聊聊线程安全
- zzulioj--1777--和尚特烦恼3——何时能下山(水题)