通知基本用法NSNotificationCenter

关于iOS中的通知中心(NSNotificationCenter) 先说一下什么叫通知: iOS中的通知机制又叫消息机制,其包括2类:一类是本地通知;另一类是推送通知,也叫远程通知.两种通知在iOS中的表现一致,可以通过横幅或者弹出提醒两种形式告诉用户,并且点击通知可以打开应用程序,但是两种通知的实现原理却完全不同.那么什么是通知中心呢: 对于初学者,往往会把iOS中的本地通知,推送通知和iOS通知中心的概念弄混.其实二者之间并没有任何关系,事实上它们都不属于一 阅读详情


//第一个viewcontriller

@implementation testViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

   

}

- (IBAction)postBtn:(id)sender {

 //发送通知第一种方法:初始化一个通知在用通知中心发送

//     NSNotification *nofi = [NSNotification notificationWithName:@"testnoti" object:nil userInfo:@{@"zyc":@"123"}];

//    [[NSNotificationCenter defaultCenter]postNotification:nofi];

 //发送通知第二种方法:直接通知中心发送  object和userinfo都是通知的属性

    [[NSNotificationCenter defaultCenter]postNotificationName:@"testnoti" object:@"1" userInfo:@{@"zyc":@"123"}];

}



//第二个viewcontriller

@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    //添加监听 然后执行操作

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(aa:) name:@"testnoti" object:nil];

}

//执行操作

- (void)aa:(NSNotification *)sender{

    NSLog(@"%@",sender);//可以利用通知属性 object userinfo 传值过来

}

- (IBAction)pushto:(id)sender {

    testViewController *testvc = [[testViewController alloc]init];

    [self.navigationController pushViewController:testvc animated:YES];

}


PyCharm旧版本下载地址 快捷找到PyCharm历史版本下载地址 阅读详情

相关推荐

设计的多实例引用(Multiple Instances of a Design Reference)

一、什么是“设计的多实例引用” 在层次化的设计中,我们经常会将一个module例化多份,这些例化的instance就是设计的module的多实例引用。 二、为什么要解决多实例引用 三、怎么解决多实例引用 ...

kevindas的博客 3719

NSNotificationCenter通知基本用法(二)

续上一篇NSNotificationCenter通知基本用法(一) 系统自带的通知,例如:UITextField - (void)viewDidLoad { [super viewDidLoad]; //UIApplicationWillResignActiveNotification将要失去活动状态的通知 [[NSNotificationCent

MinggeQingchun的博客 801

机器学习系列(3)_逻辑回归应用之Kaggle泰坦尼克之灾

f作者: 寒小阳 &&龙心尘 时间:2015年10月。 出处: 声明:版权所有,转载请注明出处,谢谢。手把手机器学习之逻辑回归应用——Kaggle泰坦尼克之灾1.引言先说一句,年末双十一什么的一来,真是非(mang)常(cheng)欢(gou)乐(le)!然后push自己抽出时间来写这篇blog的原因也非常简单: 写完前两篇逻辑回归的介绍和各个角度理解之后,小伙伴们纷纷表示『好像很高级的样纸,

寒小阳 43万+

NSNotificationCenter通知基本用法(一)

ViewController.m文件中 - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveChangeColorNotification:) name:@"changeCol

MinggeQingchun的博客 674

Windows 高精度计时器:QueryPerformanceCounter 原理、陷阱与最佳实践

本文深入解析Windows高精度计时器QueryPerformanceCounter(QPC)的工作原理、常见陷阱及最佳实践。QPC通过读取硬件计时器(如TSC)实现微秒级精度,适用于游戏开发、音视频处理等高性能场景。文章详细探讨了多核同步、动态频率调整等挑战,并提供了优化代码示例和性能对比数据。

weixin_33391446的博客 271

24、水下传感器网络中混合LEACH协议与遗传算法获取路由节点

本文提出了一种结合遗传算法与LEACH协议的混合路由方案,用于提升水下无线传感器网络(UWSN)的能量利用效率和数据传输稳定性。通过遗传算法优化簇头选择与路径规划,有效避免节点过早死亡,减少能量消耗,在200个节点场景下显著提升网络寿命。相比传统LEACH协议,该方案具有更高的能量利用率、更强的环境适应性,并支持传输历史记录与并行传输序列。实验结果显示,该方案在总能量为2000焦耳时剩余能量达75.6%,远优于LEACH的34.8%能耗表现。适用于海洋监测、石油平台监控及水下灾害预警等复杂环境应用。

i8j9k0l1的博客 112

object c NSNotificationCenter 通知中心

Object C的NSNotificationCenter类似android的广播 Objective-C 1234567891011121314@implementation Boss-(void)sendNotification{    //发送通知    NSDictionary

ifengkeyi的博客 602

Qt实现YOLO目标检测及其界面制作(附完整源码)

Qt实现YOLO目标检测及其界面制作(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 2739

NSNotificationCenter通知的基础使用

NSNotificationCenter通知的使用方法详解

weixin_47949250的博客 165

详解FreeRTOS:低功耗Tickless模式(高级篇—7)

FreeRTOS提供了一个叫做Tickless的低功耗模式,本篇博文我们就来学习一下如何使用这个Tickless模式。

不脱发的程序猿 1898

使用RV1126实现人脸识别——将Facenet模型转换为RKNN模型

在本文中,我们将探讨如何在RV1126芯片上实现人脸识别,并将Facenet模型转换为RKNN(Rockchip Neural Network)模型,以在RV1126上进行高效的人脸识别。Fine-tuning是指在预训练模型的基础上,使用自己的数据集进行进一步训练,以适应特定的任务。同时,我们需要下载Facenet模型的预训练权重,这些权重将作为我们的基础模型。综上所述,我们详细介绍了如何在RV1126上实现人脸识别,并将Facenet模型转换为RKNN模型。方法将模型导出为RKNN格式的文件。

code_program481的博客 1522

IOS中通知中心NSNotificationCenter应用总结

一.了解几个相关的类 1. NSNotification 这个类可以理解为一个消息对象, 其中有三个成员变量. 这个成员变量是这个消息对象的唯一标识,用于辨别消息对象 @property (readonly, copy) NSString *name; 这个成员变量定义一个对象, 可以理解为针对某个对象的消息 @property (readonly, retain) id object

Heath 986

构建高效的LLM应用测试框架

《构建高效的LLM应用测试框架》 关键词:LLM,测试框架,应用测试,效率优化,测试原理 摘要:本文将深入探讨构建高效LLM应用测试框架的必要性、方法与步骤,旨在为开发者提供一套系统化、可操作的测试解决方案,从而提升LLM

AI天才研究院 1048

iOS中使用通知传递参数问题

[[NSNotificationCenter defaultCenter] addObserver:self   selector:@selector(doSomeThing)  name:@“XXX”   object:要传递的对象];  后面的参数object就是传对象的,在之后的selector中是这样写的 - (void)doSomeThing:(NSNotification *)

中国iOS开发者协会官方博客 825

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

iOS 通知中心 NSNotificationCenter & NSNotification

通知中心是 Foundation 框架的一个子系统,它向应用程序中注册为某个事件观察者的所有对象广播消息(即通知)。(从编程角度而言,它是 NSNotificationCenter 类的实例)。该事件可以是发生在应用程序中的任何事情,例如进入后台状态,或者用户开始在文本栏中键入。通知是告诉观察者,事件已经发生或即将发生,因此让观察者有机会以合适的方式响应。通过通知中心来传播通知,是增加应用程序对象

小邓笔记 2万+

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

iOS NSNotificationCenter 接收不到通知消息

作者:Gintok 链接:https://www.jianshu.com/p/e368a18ca7c2 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 通知的使用 NSNotificationCenter通知中心是iOS程序内部的一种消息广播的实现机制,可以在不同对象之间发送通知进而实现通信,通知中心采用的是一对多的方式,一个对象发送的通知可以被多个对象...

Lee优快云77的博客 2877

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

iOS中通知中心NSNotificationCenter应用总结

iOS中通知中心NSNotificationCenter应用总结 一、了解几个相关的类 1、NSNotification 这个类可以理解为一个消息对象,其中有三个成员变量。 这个成员变量是这个消息对象的唯一标识,用于辨别消息对象。 @property (readonly, copy) NSString *name;   这个成员变量定义一个对象,可

LG_CodeMachine的博客 680

ios 通知接收两次_iOS中通知中心(NSNotificationCenter)的使用总结

iOS中通知中心NSNotificationCenter应用总结一、了解几个相关的类1、NSNotification这个类可以理解为一个消息对象,其中有三个成员变量。这个成员变量是这个消息对象的唯一标识,用于辨别消息对象。@property(readonly,copy)NSString*name;这个成员变量定义一个对象,可以理解为针对某一个对象的消息。@property(readonly,ret...

weixin_39735288的博客 744

iOS中通知的使用NSNotificationCenter

在实际的开发中,通知这一手段还是比较常用的。那今天就详细讲讲通知。 1.通知中心(NSNotificationCenter)实际是在程序内部提供了一种广播机制。把接收到的消息,根据内部的消息转发表,将消息转发给需要的对象。这句话其实已经很明显的告诉我们要如何使用通知了。第一步:在需要的地方注册要观察的通知,第二步:在某地方发送通知。(这里注意:发送的通知可能是我们自定义的,也可能是系统的)。

gujinyue 2万+

通知中心(NSNotificationCenter)

今天来跟大家分享一个下通知中心(NSNotificationCenter),也有称之为观察者模式的。这个模式在IOS开发同代理模式相类似,也主要用于监听。但是却有本质的区别,因为我们在使用代理模式进行开发的时候,一般都是一对一的监听和回调。而通知中心,实现了多对多的机制。 对于通知中心,我们要通过三个方面来学习 1.通知的发布,也有人称之为注册 2.通知的监听 3.通知的移除 ...

QQ644387925的博客 371

IOS中通知中心(NSNotificationCenter)的使用总结

IOS中通知中心NSNotificationCenter应用总结 一、了解几个相关的类 1、NSNotification 这个类可以理解为一个消息对象,其中有三个成员变量。 这个成员变量是这个消息对象的唯一标识,用于辨别消息对象。 @property(readonly,copy)NSString*name; 这个成员变量定义一个对象,可以理解为针对某一个对...

ayaya001100的博客 136

NSNotificationCenter 用法详解

作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的. 注册通知:即要在什么地方接受消息                [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(mytest:) name:@" mytest" object:nil]; 

齐恒毅-博客专栏 607

ios 通知注销_iOS 通知中心(NSNotificationCenter)

NSNotificationCenter在这里第一步和第二步的顺序可以互换,一般楼主我喜欢先在需要发送消息的页面发送消息,然后再在需要监听的页面注册监听。要注意的是不管是通知中心还是KVO都需要在页面销毁之前移除监听。注册观察者/*** 观察者注册消息通知** @param addObserver 观察者 self** @param selector 回调方法 n...

weixin_39873208的博客 375

IOS NSNotificationCenter 通知中心

今天我们来了解一下 NSNotificationCenter 消息通知中心这个类 一个NSNotificationCenter对象在一个程序内,提供一个广播消息的机制 一个NSNotificationCenter对象从本质上来说是一个通知调度表 每一个正在运行的程序都有一个默认的通知中心,所以你一般不用创建自己 的通知中心,并且一个NSNotificationCenter对象只能在单个

iOS 刘通超 2449

NSNotificationCenter通知

NSNotificationCenter 相比与 Delegate 可以实现更大的跨度的通信机制,可以为多个无引用关系的对象进行通信。 利用通知逆向传值:通知的使用首先注册获取通知中心单例  (1)       //1.获取通知中心         NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

zxcsai的博客 325

NSNotificationCenter 传递带参数的通知

NSNotificationCenter  在  init里面注册这个通知, NSString* const str = @"FuckMe";    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(on:)   name:str object:nil]; 在dealloc里面移

brasbug的专栏 1374
上一篇: 键盘上添加toolbar 添加Button
下一篇: 利用通知监测键盘高度
SpringJustin
博客等级 码龄11年 2粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值