关于一个 view controller 里的不同 UIActionSheet 使用同一个 delegate 的问题 - V2EX
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
Livid
231.35D
549.87D
V2EX    iDev

关于一个 view controller 里的不同 UIActionSheet 使用同一个 delegate 的问题

  •  
  •   Livid
    PRO
    2012 年 2 月 27 日 7166 次点击
    这是一个创建于 5066 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如果,在同一个 UIViewController 里,两个不同的按钮触发了两个不同的 UIActionSheet,然后这两个 UIActionSheet 的 delegate 都是这个 UIViewController 本身,那么大家会用什么样的办法在实现 delegate 的响应方法时区分不同的 UIActionSheet 呢?

    或者,有更好的设计模式?
    19 条回复    1970-01-01 08:00:00 +08:00
    Livid
        1
    Livid  
    MOD
    OP
    PRO
       2012 年 2 月 27 日
    我目前在用的一种方式是,为这些不同的 UIActionSheet 分配不同的 tag,然后在 delegate 的响应方法里做判断。

    所以我好奇是否还有其他更好的方法?
    ydhydh
        2
    ydhydh  
       2012 年 2 月 27 日
    根据 buttonTitle ??

    buttonTitleAtIndex
    Fann
        3
    Fann  
       2012 年 2 月 27 日
    同样用 tag 来区分处理,不同的 UIAlertView 也是用 tag 区分。
    fly2never
        4
    fly2never  
       2012 年 2 月 27 日
    目前也是tag区分,还发现什么不好
    Livid
        5
    Livid  
    MOD
    OP
    PRO
       2012 年 2 月 27 日
    那么,如果就是用 tag 来区分的话,在 tag 的编码上,大家是否有什么好的规则心得可以分享一下呢?
    ydhydh
        6
    ydhydh  
       2012 年 2 月 27 日
    @Livid 汗,理解错误,以为最终目的是区分button呢,考虑下block?
    froo
        7
    froo  
       2012 年 2 月 27 日
    UIActionSheet *sheet1;
    UIActionSheet *sheet2;

    然后在Delegate中用if来判断
    if (actiOnsheet== sheet1 ){}, if (actiOnsheet== sheet2 ){} ……

    这样可读性应该好一些。
    Kai
        8
    Kai  
       2012 年 2 月 27 日 via iPhone
    同 @froo 的方法,感觉清楚一些。
    doskoi
        9
    doskoi  
       2012 年 2 月 27 日
    TAG可以定义成enum

    enum {
    kAlertView,
    kInfomationView,
    kWarningView,
    kErrorView
    }

    然后tag = Alertview.tag;

    switch tag, case不同tag做处理
    levey
        10
    levey  
       2012 年 2 月 27 日
    要么用类的变量,要么用tag,我喜欢后者。as.tag = 0x2001
    Fann
        11
    Fann  
       2012 年 2 月 27 日
    @doskoi +1.
    linlinqi
        12
    linlinqi  
       2012 年 2 月 27 日
    我试过用actionSheet的title来判断当它们的标题不一样的时候
    sawyerzhang
        13
    sawyerzhang  
       2012 年 2 月 27 日
    同意 @froo, 直接在IB里面拉很方便的。
    BB9z
        14
    BB9z  
       2012 年 2 月 27 日
    喜欢 @doskoi 的方法。
    lldong
        15
    lldong  
       2012 年 2 月 27 日
    支持用tag,而且tag是NSInteger类型,能保证存得下一个指针,有时可以利用这点保存一些和该view关联的信息。
    avatasia
        16
    avatasia  
       2012 年 2 月 28 日
    public class UIActionSheet
    {
    public static UIActionShee Sheet1 = new UIActionSheet ("Sheet1");
    public static UIActionSheet Sheet2 = new UIActionSheet ("Sheet2");
    private UIActionSheet (string type)
    {
    }
    }

    UIController(UIActionSheet sheet)
    {
    }

    随便写的
    elden
        17
    elden  
       2012 年 2 月 28 日
    Blocks
    Shane
        19
    Shane  
       2012 年 3 月 1 日
    @lex +1 这个不错
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     924 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 20:02 PVG 04:02 LAX 12:02 JFK 15:02
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86