• 请不要在回答技术问题时复制粘贴 AI 生成的内容
androidBrant
V2EX  ›  程序员

给 UITextView 添加 placeHolder 的一个 Category

  •  
  •   androidBrant · Aug 8, 2014 · 5127 views
    This topic created in 4473 days ago, the information mentioned may be changed or developed.
    7 replies  •  2014-08-09 02:20:29 +08:00
    black
    black
    Aug 8, 2014
    1
    把delegate指向了自己,不太好吧
    androidBrant
    androidBrant
    OP
    Aug 8, 2014
    2
    @black assign的,我又没有引用他,不会内存泄漏啊
    railgun
    railgun
    Aug 8, 2014
    3
    问题是真正想用这个协议的人就用不了了啊
    改用通知吧
    black
    black
    Aug 8, 2014
    4
    @railgun +1,我想说的就是这个,不过楼主也说了现在还没有完善delegate的传递,楼主加油~
    zhigang1992
    zhigang1992
    Aug 8, 2014
    5
    用通知,
    UIKIT_EXTERN NSString * const UITextViewTextDidBeginEditingNotification;
    UIKIT_EXTERN NSString * const UITextViewTextDidChangeNotification;
    UIKIT_EXTERN NSString * const UITextViewTextDidEndEditingNotification;
    但是问题是不能在Category中很方便的override dealloc来取消通知~~~

    http://www.merowing.info/2012/03/automatic-removal-of-nsnotificationcenter-or-kvo-observers/#.U-Sx64CSxhY

    just my two cents
    zhigang1992
    zhigang1992
    Aug 8, 2014
    6
    或者:
    把setDelegate方法重写了,把值写到一个runTime的property里面~
    然后在category里面用setValueForKeyPath来设置delegate。
    最后在所有的method里面调对应property的method
    hoogle
    hoogle
    Aug 9, 2014 via iPhone
    7
    这个功能的实现 考虑用继承比Category合适。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1957 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 03:43 · PVG 11:43 · LAX 19:43 · JFK 22:43
    ♥ Do have faith in what you're doing.