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 · Mar 26, 2015 · 2746 views
    This topic created in 4101 days ago, the information mentioned may be changed or developed.
    各位都知道,设置了 xxx.delegate = self 后,需要在 dealloc 之类的地方 xxx.delegate = nil

    那么,如果是在 IB 里设置了 tableview.delegate = file's owner
    应该在哪里设置 .delegate = nil 呢?
    还是不用设置?
    8 replies    2015-04-14 10:57:58 +08:00
    walkingway
        1
    walkingway  
       Mar 26, 2015
    如果 tableview 只有 tableviewController 指向(strong)他,就不用,因为 tableviewController 销毁了,tableview 也跟着销毁了,当然 delegate 要设成 weak。
    georgetso
        2
    georgetso  
    OP
       Mar 27, 2015
    @walkingway 我是说在 interface builder 里的做法
    huanglexus
        3
    huanglexus  
       Mar 27, 2015 via iPhone   ❤️ 1
    不用设置。。
    代码写也不用写这多余的delegate=nil
    因为这是weak指针。
    LMkillme
        4
    LMkillme  
       Mar 27, 2015   ❤️ 1
    @georgetso ib里面也是weak :-D
    georgetso
        5
    georgetso  
    OP
       Mar 27, 2015
    已感谢
    yetAnotherJoe
        6
    yetAnotherJoe  
       Mar 27, 2015
    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  
       Apr 1, 2015
    保持良好习惯dealloc 里面制空。
    kobe1941
        8
    kobe1941  
       Apr 14, 2015
    delegate一直用weak修饰,不用在dealloc里设置为nil,多此一举(ARC下)。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5485 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 359ms · UTC 02:40 · PVG 10:40 · LAX 19:40 · JFK 22:40
    ♥ Do have faith in what you're doing.