zoukankan      html  css  js  c++  java
  • 自定义UIView怎么注册销毁NSNotification通知

    问题描述:在使用天猫tangram框架后。部分组件自定义后会用到通知,但是在iOS 8 系统中,会崩溃?

    原因分析:当对象挂掉后,要对应移除注册的通知。 否则当你重复执行发送通知的时候,在iOS8 系统以下,就会崩溃(其他系统暂时没有发现)。我们需要
    在接受通知的类里移除通知。但是对于自定义的UIView类,该怎么操作呢?

    方案解决:

    //移除通知方法'
    - (void)willMoveToWindow:(UIWindow*)newWindow {
        if(newWindow == nil) {
            // Will be removed from window, similar to -viewDidUnload.'
            // Unsubscribe from any notifications here.'
            [[NSNotificationCenterdefaultCenter] removeObserver:self];
        }
    }
    //添加通知方法'
    - (void)didMoveToWindow {
        if(self.window) {
            // Added to a window, similar to -viewDidLoad.'
            // Subscribe to notifications here.'
            [PublicFunctionaddObserver:selfnotificationName:@"refreshTheOpPersonalActivity"selector:@selector(clearTheArryData) object:nil];
        }
    }
  • 相关阅读:
    freeswitch录音功能
    jdk安装
    maven阿里云镜像
    idea安装
    idea新建maven项目
    tomcat安装
    idea新建maven web项目
    idea新建java项目
    webpack使用
    ACE 安装指南及示例
  • 原文地址:https://www.cnblogs.com/richard-youth/p/9232517.html
Copyright © 2011-2022 走看看