V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
georgetso
V2EX  ›  iDev

关于 delegate = nil 的问题

  •  
  •   georgetso · 2015-03-26 22:23:13 +08:00 · 2167 次点击
    这是一个创建于 3325 天前的主题,其中的信息可能已经有所发展或是发生改变。
    各位都知道,设置了 xxx.delegate = self 后,需要在 dealloc 之类的地方 xxx.delegate = nil

    那么,如果是在 IB 里设置了 tableview.delegate = file's owner
    应该在哪里设置 .delegate = nil 呢?
    还是不用设置?
    8 条回复    2015-04-14 10:57:58 +08:00
    walkingway
        1
    walkingway  
       2015-03-26 23:00:57 +08:00
    如果 tableview 只有 tableviewController 指向(strong)他,就不用,因为 tableviewController 销毁了,tableview 也跟着销毁了,当然 delegate 要设成 weak。
    georgetso
        2
    georgetso  
    OP
       2015-03-27 00:02:08 +08:00
    @walkingway 我是说在 interface builder 里的做法
    huanglexus
        3
    huanglexus  
       2015-03-27 00:45:31 +08:00 via iPhone   ❤️ 1
    不用设置。。
    代码写也不用写这多余的delegate=nil
    因为这是weak指针。
    LMkillme
        4
    LMkillme  
       2015-03-27 00:55:07 +08:00   ❤️ 1
    @georgetso ib里面也是weak :-D
    georgetso
        5
    georgetso  
    OP
       2015-03-27 09:21:20 +08:00
    已感谢
    xuzhongzhou
        6
    xuzhongzhou  
       2015-03-27 11:13:56 +08:00
    You do not have to (indeed cannot) release instance variables, but you may need to invoke [self setDelegate:nil] on system classes and other code that isn’t compiled using ARC.
    kepenj
        7
    kepenj  
       2015-04-01 14:13:18 +08:00
    保持良好习惯dealloc 里面制空。
    kobe1941
        8
    kobe1941  
       2015-04-14 10:57:58 +08:00
    delegate一直用weak修饰,不用在dealloc里设置为nil,多此一举(ARC下)。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2270 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 15:20 · PVG 23:20 · LAX 08:20 · JFK 11:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.