iPhone禁用UIActionSheet按钮 [英] iPhone Disabling UIActionSheet buttons

查看:120
本文介绍了iPhone禁用UIActionSheet按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在UIAction表中禁用按钮,并在特定条件为真后启用它们。我如何实现这一点?任何想法?

I want to disable buttons in the UIAction sheet and enable them after a certain condition is true. How do I achieve this? Any ideas?

推荐答案

我发现craig的答案没有为我工作经过一点点挖掘,我发现 UIActionSheet 的子视图实际上是一个未记录的类 UIThreePartButton

I found that craig's answer didn't work for me (on OS 3.1). After a little digging around I discovered that the subviews of UIActionSheet are actually of an undocumented class UIThreePartButton

无论如何,这适用于我(作为 UIActionSheetDelegete 方法的一部分实现)

Anyway, this works for me (implemented as part of the UIActionSheetDelegete method)

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet  // before animation and showing view
{
    for (UIView* view in [actionSheet subviews])
    {
        if ([[[view class] description] isEqualToString:@"UIThreePartButton"])
        {
            if ([view respondsToSelector:@selector(title)])
            {
                NSString* title = [view performSelector:@selector(title)];
                if ([title isEqualToString:@"Button 1"] && [view respondsToSelector:@selector(setEnabled:)])
                {
                    [view performSelector:@selector(setEnabled:) withObject:NO];
                }
            }
        }
    }
}


$ b b

希望帮助别人,虽然我会回应Ed Marty的问题,你是否会更好,只是从操作表中省略这些按钮,而不是这样做。与使用未记录的功能一样,存在应用商店拒绝的风险,但如果Apple在未来的操作系统版本中再次执行API,该代码将无法正常写入。

Hope that helps someone else, although I'd echo Ed Marty's question of whether you'd be better off just omitting these buttons from the action sheet altogether instead of doing this. As always when using undocumented features, there is a risk of app store rejection, although this code is written to fail gracefully if Apple do chnage the APIs again in a future OS release.

这篇关于iPhone禁用UIActionSheet按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆