取消按钮和 UIActionSheet 的问题
如何确定 UIActionSheet 上的取消按钮是否被按下?
我的 UIActionSheet 设置如下:
-(IBAction)fileButtonPressed
{
UIActionSheet *mymenu = [[UIActionSheet alloc]
initWithTitle:@"Select Folder"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (i=0; i<3; i++)
{
[mymenu addButtonWithTitle:@"Button Name"];
}
[mymenu showInView:self.view];
}
我遇到的问题是我无法区分取消按钮和选择的第一个按钮。
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *option = [actionSheet buttonTitleAtIndex:buttonIndex];
//buttonIndex == 0 if the cancel button is pressed or
//if the first item is pressed.
}
有更好的方法来设置这个吗?
How do I determine if the cancel button was pressed on a UIActionSheet?
My UIActionSheet is set up like this:
-(IBAction)fileButtonPressed
{
UIActionSheet *mymenu = [[UIActionSheet alloc]
initWithTitle:@"Select Folder"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (i=0; i<3; i++)
{
[mymenu addButtonWithTitle:@"Button Name"];
}
[mymenu showInView:self.view];
}
The problem that I have is that I cannot differentiate between the cancel button and the first button selected.
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *option = [actionSheet buttonTitleAtIndex:buttonIndex];
//buttonIndex == 0 if the cancel button is pressed or
//if the first item is pressed.
}
Is there a better way of setting this up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明,诀窍是不使用自动取消按钮,而是自己添加它。
另一个小问题是在末尾而不是开头添加取消按钮。
归功于此 stackoverflow 条目的答案。
The trick turns out to be not to use the automatic cancel button but to add it yourself.
The other slight gotcha is to add the cancel button at the end and not at the beginning.
credit to this stackoverflow entry for the answer.
UIActionSheet 还具有可比较的属性,如
damulatoryButtonIndex
和firstOtherButtonIndex
。UIActionSheet also has properties like
destructiveButtonIndex
andfirstOtherButtonIndex
to compare against.添加这个
[mymenu showInView:self.parentViewController.tabBarController.view];
add this
[mymenu showInView:self.parentViewController.tabBarController.view];