• 自定义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];
        }
    }
  • 相关阅读:
    win10通过ip连接打印机
    tarunexpectedeofinarchive
    软件工程设计阶段的几种图
    代码review checklist
    caffeine的使用
    thetrustanchorsparametermustbenonempty
    mysql explain type的详解
    scp对拷贝文件夹
    虚拟dom与diff算法
    线程池ThreadPoolExecutor的使用
  • 原文地址:https://www.cnblogs.com/richard-youth/p/9232517.html
Copyright © 2020-2023  润新知