简体   繁体   English

NSObject类工作

[英]NSObject class working

I am using NSObject class in my project and I want to use network indicator in NSObject class like when I call any function of that class network indication starts and once code comes out from class, network indicator stops. 我在项目中使用NSObject类,并且想在NSObject类中使用网络指示器,就像当我调用该类的任何功能时,网络指示器开始并且一旦代码从类中出来后,网络指示器就停止了。

For starting network indicator, I am using initialize() function as: 为了启动网络指示器,我将initialize()函数用作:

override class func initialize () {
    UIApplication.sharedApplication().networkActivityIndicatorVisible = true
}

Now I want to know in which function, I stop network indicator. 现在我想知道停止网络指示器的功能。 Basically which function call at last in NSObject class? 基本上, NSObject类中最后哪个函数调用?

您可能可以实现-dealloc方法,该方法仅在删除对象时才调用。

If the deinit( ) method is not working it means that you are not deallocating the object properly, you may have a memory leak there(only if you're intetionally make it work deallocating the object). 如果deinit( )方法不起作用,则意味着您没有正确地释放对象,则那里可能存在内存泄漏(仅当您使它有效地释放对象时才如此)。

Another approach would be a defer {} implementation in the methods that would set the indicator to true. 另一种方法是将指标设置为true的方法中的defer {}实现。

func myMethod(){
    defer{
        UIApplication.sharedApplication().networkActivityIndicatorVisible = false
    }
} 

If you're using func initialize() you probably can use func finalize() 如果您使用func initialize() ,则可能可以使用func finalize()

override class func finalize () {
    UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM