【问题标题】:UIActionSheet buttonIndexUIActionSheet buttonIndex
【发布时间】:2012-01-17 10:10:38
【问题描述】:

我的应用中有一个 UIActionSheet,它默认有 4 个按钮。如果用户自定义图像,则操作表会获得额外的第 5 个按钮,允许用户重置此图像。

我正在使用此委托方法来确定单击了哪个操作表按钮:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

问题是取消按钮默认位于 buttonIndex 2,但当第 5 个按钮出现时,它位于 buttonIndex 3。知道 buttonIndex 后,您是否可以访问操作表按钮的标题/名称?

【问题讨论】:

    标签: iphone ios uiactionsheet


    【解决方案1】:

    是的,您可以使用以下命令向操作表询问给定索引处的按钮标题:

    -(NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
    

    或者,UIActionSheet 定义一个属性:

    @property(nonatomic) NSInteger cancelButtonIndex;
    

    【讨论】:

    • 啊太棒了,效果很好。查看文档时完全错过了该方法。感谢您如此迅速的回复。
    • 最后决定使用cancelButtonIndex 属性,好像取消按钮标题发生变化(不太可能)代码不会中断。
    • 确保 buttonIndex >=0 并且
    • 最好将cancelButtonIndex AND buttonTitleAtIndex用于“其他按钮”,因为ios可以决定对按钮进行处理(取消可能在顶部或底部,也可以销毁)
    猜你喜欢
    • 1970-01-01
    • 2014-08-30
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多