取消按钮和UIActionSheet的问题
问题描述:
如何确定取消按钮是否在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.
}
有没有更好的设置方法?
答
诀窍结果是不使用自动取消按钮,而是自己添加它。
另一个小问题是在最后添加取消按钮而不是开始。
-(IBAction)fileButtonPressed
{
UIActionSheet *mymenu = [[UIActionSheet alloc]
initWithTitle:@"Select Folder"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (int nb=0; nb<3; nb++)
{
[mymenu addButtonWithTitle:@"Button Name"];
}
mymenu.cancelButtonIndex = [mymenu addButtonWithTitle: @"Cancel"];
[mymenu showInView:self.view];
}
信贷这个*条目答案。
答
if (buttonIndex == actionSheet.cancelButtonIndex)
{
// Handle cancel action
}
UIActionSheet也有像destructiveButtonIndex
和firstOtherButtonIndex
特性来比较。
答
添加此
[MyMenu菜单showInView:self.parentViewController.tabBarController.view];
非常好,谢谢 – shannoga 2013-10-30 15:19:54
UIActionSheet必须是所有iOS中最繁琐的一段代码 – bugfixr 2014-02-17 13:04:20