iPhone Disabling UIActionSheet buttons

后端 未结 7 886
梦谈多话
梦谈多话 2020-12-10 16:01

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?

7条回答
  •  再見小時候
    2020-12-10 16:04

    Is there a circumstance that can change, while the action sheet is open, that could cause the button to become enabled? If not, I think the better approach is to alter the buttons that the sheet displays based on your condition.

    Otherwise, the only way of handling this is to iterate through the sheet's subviews, like Craig said, and look for the UIButton objects. I'd be careful about using the button's title, though, because the title could (and should!) be localized for different languages. So comparisons against the title aren't all that reliable. Since you didn't create the button, you don't really know what the tag or action of each button would be, either, so that's a bit difficult, too.

    Presumably, the buttons will appear in the subviews array in the order you specified them to the UIActionSheet, but since this isn't documented, there's no guarantee that they will appear in that order, or that they will continue to appear in that order in future releases of the Cocoa Touch SDK. Because of that, I'd worry mainly about being rejected from the App Store for using undocumented functionality.

提交回复
热议问题