首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏iOS 开发杂谈

    浅谈 iOS NSNotification

    可以实现一对多,NSNotification 的实际是一种观察者模式。 NSNotification NSNotification 是 NSNotificationCenter 接收到消息之后根据内部的消息转发表,将消息发送给订阅者封装的对象; @interface NSNotification 属性都是只读的,如果要创建通知则要用下面 NSNotification(NSNotificationCreation) 分类相应的方法进行初始化; NSNotification 不能通过 init 实例化 ,这样会引起下面的异常,比如: NSNotification *notif = [[NSNotification alloc] init]; *** Terminating app due to uncaught block 上面苹果官方给我们提供的方法外,我们还可以利用基于 block 的 NSNotification 去实现,apple 从 ios4 之后提供了带有 block 的 NSNotification

    1.6K30发布于 2018-09-30
  • 来自专栏日常技术分享

    iOS NSNotificationCenter通知中心的实现原理

    ---- NSNotification NSNotification是方便NSNotificationCenter广播到其他对象时的封装对象,简单讲即通知中心对通知调度表中的对象广播时发送NSNotification NSNotification的工作机制 1.应用程序中需要订阅通知的对象,会向通告中心(Notification Center,NSNotificationCenter类的实例)注册,从而成为该事件的监听者 2.监听对象发生变化后,对象给通告中心发一个通告(NSnotification的实例)。该通告对象包括识别通告的标志、发布通告的对象ID和可选的附加信息字典。 @interface NSNotification : NSObject <NSCopying, NSCoding> @property (readonly, copy) NSNotificationName 在通知中心注册观察者,发送者使用通知中心广播时,以NSNotification的name和object来确定需要发送给哪个观察者。

    2.7K30发布于 2020-06-16
  • 来自专栏一“技”之长

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

    iOS中通知中心NSNotificationCenter应用总结 一、了解几个相关的类 1、NSNotification 这个类可以理解为一个消息对象,其中有三个成员变量。 @property (readonly, copy) NSDictionary *userInfo; NSNotification的初始化方法: - (instancetype)initWithName selector:(SEL)aSelector name:(NSString *)aName object:(id)anObject; 发送通知消息的方法 - (void)postNotification:(NSNotification addObserver:self selector:@selector(notice:) name:@"123" object:nil]; 之后,在我们需要时发送通知消息     //创建一个消息对象     NSNotification  * notice = [NSNotification notificationWithName:@"123" object:nil userInfo:@{@"1":@"123"}];     //发送消息

    1.1K30发布于 2018-08-15
  • 来自专栏iOS技术杂谈

    NSNotificationCenter 通知的使用方法详解你要知道的KVC、KVO、Delegate、Notification都在这里

    首先看一下比较重要的NSNotification类,这是通知中心的基础,通知中心发送的的通知都会封装成该类的对象进而在不同对象之间传递。 //字典类型的用户信息,用户可将需要传递的数据放入该字典中 @property (nullable, readonly, copy) NSDictionary *userInfo; //下面三个是NSNotification (NSNotificationName)aName object:(nullable id)anObject userInfo:(nullable NSDictionary *)aUserInfo; NSNotification SEL)aSelector name:(nullable NSNotificationName)aName object:(nullable id)anObject; /* 发送通知,需要手动构造一个NSNotification 对象 */ - (void)postNotification:(NSNotification *)notification; /* 发送通知 aName为注册的通知名称 anObject为接受通知的对象

    2.7K60发布于 2018-04-10
  • 来自专栏python3

    Unity3D 接入IOS SDK

    @protocol SDKLifeCycleListener <NSObject> @optional - (void)didFinishLaunching:(NSNotification*)notification ; - (void)didBecomeActive:(NSNotification*)notification; - (void)willResignActive:(NSNotification*)notification ; - (void)didEnterBackground:(NSNotification*)notification; - (void)willEnterForeground:(NSNotification *)notification; - (void)willTerminate:(NSNotification*)notification; @end //注册生命周期回调函数 void SDKRegisterLifeCycleListener

    3.1K11发布于 2020-01-07
  • 来自专栏github@hornhuang

    【iOS】如何在 NSViewController、NSView 中关闭当前 NSWindowController ?

    @objc func terminateWindow(notification: NSNotification) { ... @objc func terminateWindow(notification: NSNotification) { ... 我帮他家搜寻了一番,终于找到了正解 extension LoginViewController { @objc func onSucceed(notification: NSNotification close() ... } @objc func onFailed(notification: NSNotification) { /// TODO

    1.5K20编辑于 2021-12-30
  • 来自专栏github@hornhuang

    【iOS】如何在 NSViewController、NSView 中关闭当前 NSWindowController ?

    @objc func terminateWindow(notification: NSNotification) { ... @objc func terminateWindow(notification: NSNotification) { ... 我帮他家搜寻了一番,终于找到了正解 extension LoginViewController { @objc func onSucceed(notification: NSNotification close() ... } @objc func onFailed(notification: NSNotification) { /// TODO

    1.6K40发布于 2021-09-24
  • 来自专栏每日一篇技术文章

    Swift3.0 - 键盘相关

    NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillShow(notification:)), name: NSNotification.Name.UIKeyboardWillShow NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillHide(notification:)), name: NSNotification.Name.UIKeyboardWillHide

    43120发布于 2018-09-14
  • 来自专栏码客

    iOS听筒和外放切换

    NotificationCenter.default.addObserver(self, selector: #selector(ChatViewController.sensorStateChange(_:)), name: NSNotification.Name.UIDeviceProximityStateDidChange UIDevice.current.isProximityMonitoringEnabled = false; NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceProximityStateDidChange

    1.3K10发布于 2019-10-22
  • 来自专栏码客

    iOS 判断监听网络状态

    NotificationCenter.default.addObserver( self, selector: #selector(reachabilityChanged), name: NSNotification.Name.reachabilityChanged startNotifier() } @objc func reachabilityChanged(notification: NSNotification) { if self.reach!. NotificationCenter.default.addObserver( self, selector: #selector(reachabilityChanged), name: NSNotification.Name.realReachabilityChanged startNotifier(); } @objc func reachabilityChanged(notification: NSNotification) { let status

    3.4K20发布于 2019-10-22
  • 来自专栏一“技”之长

    OS X开发:NSTextField文本输入框

    返回值决定是否允许结束编辑 - (BOOL)textShouldEndEditing:(NSText *)textObject; //已经开始编辑时调用 - (void)textDidBeginEditing:(NSNotification *)notification; //已经结束编辑时调用 - (void)textDidEndEditing:(NSNotification *)notification; //文本改变时调用 - (void )textDidChange:(NSNotification *)notification; //下面这些方法用来快捷创建NSTextField + (instancetype)labelWithString

    2.4K30发布于 2018-08-15
  • 来自专栏DannyHoo的专栏

    iOS开发中微信支付集成

    isKindOfClass:[PayResp class]]){ switch (resp.errCode) { case WXSuccess:{ //支付返回结果,实际支付结果需要去自己的服务器端查询 NSNotification *notification = [NSNotification notificationWithName:@"ORDER_PAY_NOTIFICATION" object:@"success"];                 NSNotificationCenter defaultCenter] postNotification:notification]; break;             } default:{ NSNotification *notification = [NSNotification notificationWithName:@"ORDER_PAY_NOTIFICATION"object:@"fail"];                 ORDER_PAY_NOTIFICATION" object:nil]; 对监听到的消息进行处理: #pragma mark - 收到支付成功的消息后作相应的处理 - (void)getOrderPayResult:(NSNotification

    2.1K30发布于 2018-09-13
  • 来自专栏Alice

    ios textView跟随键盘的移动

    UIKeyboardWillChangeFrameNotification object:nil]; } 3.实现监听 #pragma mark-键盘出现隐藏事件 -(void)keyHiden:(NSNotification CGAffineTransformIdentity; // commentView.hidden = YES; }]; } -(void)keyWillAppear:(NSNotification

    2.1K50发布于 2018-02-01
  • 来自专栏码生

    Reveal Swift3.0使用

    , 2) command alias swift_reveal_start expr NotificationCenter.default.post(name: NSNotification.Name( IBARevealRequestStart"), object: nil) command alias swift_reveal_stop expr NotificationCenter.default.post(name: NSNotification.Name

    65120发布于 2018-11-21
  • 来自专栏css小迷妹

    IOS开发—网络监听

    startNotifier]; [self updateInterfaceWithReachability:_reachability]; 实现两个方法: - (void) reachabilityChanged: (NSNotification (Reachability*) curReach;//处理连接改变后的情况 下面是方法的具体实现,可根据情况自行改变: // 连接改变 - (void) reachabilityChanged: (NSNotification

    52900发布于 2021-09-23
  • 来自专栏家劲

    iOS 开发之路(登陆页键盘遮挡输入框问题)一

    NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillChange(notification:)), name: NSNotification.Name.UIKeyboardWillChangeFrame self.view.endEditing(true) }     键盘改变事件,防止键盘遮住输入框 // 键盘改变 func keyboardWillChange(notification: NSNotification

    1.1K30发布于 2019-09-19
  • 来自专栏用户4669341的专栏

    IOS开发:直播系统中视频播放功能实现

    stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; return url; } // 播放状态改变 - (void)mediaPlayerPlaybackStateChange:(NSNotification break; default: break; } } // 播放完成 - (void)mediaPlayerPlaybackFinished:(NSNotification stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; return url; } // 播放状态改变 -(void)mediaPlayerPlaybackStateChange:(NSNotification break; default: break; } } // 播放完成 -(void)mediaPlayerPlaybackFinished:(NSNotification

    1.9K30发布于 2019-03-06
  • 来自专栏技术之路

    【swift学习笔记】六.访facebook登录页面

    )), name: UIKeyboardWillHideNotification, object: nil) } func keyboardWillShow(notification: NSNotification } ) } } func keyboardWillHide(notification: NSNotification

    1K80发布于 2018-01-31
  • 来自专栏ShaoYL

    代理和通知

    NSnottificationCenter) 每一个应用程序都有一个通知中心(NSNotificationCenter)实例,专门负责协助不同对象之间的消息通信 任何一个对象都可以向通知中心发布通知(NSNotification (id)object; // 通知发布者(是谁要发布通知) - (NSDictionary *)userInfo; //一些额外的信息(通知发布者传递给通知接收者的信息内容) //初始化一个通知(NSNotification NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo; 发布通知 - (void)postNotification:(NSNotification 监听者 [[NSNotificationCenter defaultCenter] removeObserver:aaa]; iOS监听某些事件的方法 通知(NSNotificationCenter\NSNotification

    76650发布于 2018-05-11
  • 来自专栏好派笔记

    IOS开发—网络监听

    startNotifier]; [self updateInterfaceWithReachability:_reachability]; 实现两个方法: - (void) reachabilityChanged: (NSNotification (Reachability*) curReach;//处理连接改变后的情况 下面是方法的具体实现,可根据情况自行改变: // 连接改变 - (void) reachabilityChanged: (NSNotification

    68320发布于 2021-10-29
领券