Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在UIActionSheet中,iphone的取消按钮不显示?_Iphone_Ios_Uiactionsheet - Fatal编程技术网

在UIActionSheet中,iphone的取消按钮不显示?

在UIActionSheet中,iphone的取消按钮不显示?,iphone,ios,uiactionsheet,Iphone,Ios,Uiactionsheet,在我的应用程序中,当我单击“更改图像”时,它是一个包含三个操作的操作表。拍照、从库中选择和取消。拍照、从库中选择显示但取消未显示问题所在。 这是我的密码 - (void)viewDidLoad { [super viewDidLoad]; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:se

在我的应用程序中,当我单击“更改图像”时,它是一个包含三个操作的操作表。拍照、从库中选择和取消。拍照、从库中选择显示但取消未显示问题所在。 这是我的密码

    - (void)viewDidLoad
{
         [super viewDidLoad];
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..."
        delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from library", nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
        actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
        [actionSheet showInView:self.view];
}
试试这个

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." 
                                                         delegate:self
                                                cancelButtonTitle:@"Cancel"
                                           destructiveButtonTitle:@"Cancel"
                                                otherButtonTitles:@"Take Photo", @"Choose from library", nil];

    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view];
试试这个

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." 
                                                         delegate:self
                                                cancelButtonTitle:@"Cancel"
                                           destructiveButtonTitle:@"Cancel"
                                                otherButtonTitles:@"Take Photo", @"Choose from library", nil];

    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view];

您可能想看看在中显示操作表的替代方法。但是,您可能希望尝试使用以下选项之一(如果您有工具栏)

此外,使用以下

actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

只会导致默认的操作表样式。

您可能需要查看在中显示操作表的其他方法。但是,您可能希望尝试使用以下选项之一(如果您有工具栏)

此外,使用以下

actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
只会导致操作表样式成为默认样式。

请参阅

您也可以参考以下代码,它可能会帮助您:

(void)viewDidLoad
    {

    UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from library", nil];
    [actionSheet showInView:self.view];

    }
请参阅

您也可以参考以下代码,它可能会帮助您:

(void)viewDidLoad
    {

    UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from library", nil];
    [actionSheet showInView:self.view];

    }

这是因为…我认为您正在使用默认视图大小-视网膜4全屏作为您的视图大小…请尝试从属性检查器将您的视图大小更改为视网膜3.5全屏

这是因为…我认为您正在使用默认视图大小-视网膜4全屏作为视图大小…请尝试从属性检查器将视图大小更改为视网膜3.5全屏

因为您的问题不在于代码。可能您使用了错误的方法来显示UIActionSheet

UIActionSheet可以通过以下方法显示:

– showFromTabBar:
– showFromToolbar:
– showInView:
– showFromBarButtonItem:animated:
– showFromRect:inView:animated:
看一看


由于使用选项卡栏,取消按钮也可能位于下方。我也会对此进行测试。

因为您的问题不在于代码。可能您使用了错误的方法来显示UIActionSheet

UIActionSheet可以通过以下方法显示:

– showFromTabBar:
– showFromToolbar:
– showInView:
– showFromBarButtonItem:animated:
– showFromRect:inView:animated:
看一看



由于使用选项卡栏,取消按钮也可能位于下方。我也会对此进行测试。

两件事,您不需要将id强制转换为代理,破坏性按钮与取消按钮不同,并且此代码仍然将样式设置保持为一个选项,然后立即将其设置为另一个。@Abhijith我尝试过它引发异常2013-07-29 16:21:48.273 TestIGate[14936:c07]操作单2013-07-29 16:21:49.087 TestIGate[14936:c07]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“源类型1不可用”***第一次抛出调用堆栈:(0x1c9f012 0x10dce7e 0x2249d9 0x4278 0x416d 0x4012c1 0x10f0705 0x27920 0x278b8 0xe8671 0xe8bcf 0xe7d38 0x5733f 0x57552 0x353aa 0x26cf8 0x1BFAD0 0x1c14bf5 0x1c14962 0x1c45bb6 0x1c44f44 0x1c44e1b 0x1bf97e3 0x1bf9668 0x2465c 0x28fd 0x2825)libc++.dylib:终止引发异常(lldb)你没有在你的项目中使用ARC吗?我在我的项目中使用ARC可能是错误的,但我认为没有理由将任何对象强制转换为id。有两件事,你不需要将id强制转换为代理,破坏性按钮与取消按钮不同,这段代码仍然将样式设置为一个选项,然后立即执行正在将它转移到另一个。@Abhijith我尝试过它正在引发异常2013-07-29 16:21:48.273 TestIGate[14936:c07]actionSheet 2013-07-29 16:21:49.087 TestIGate[14936:c07]***由于未捕获的异常“NSInvalidArgumentException”终止应用程序,原因:“源类型1不可用”***第一次抛出调用堆栈:(0x1c9f012 0x10dce7e 0x2249d9 0x4278 0x416d 0x4012c1 0x10f0705 0x27920 0x278b8 0xe8671 0xe8bcf 0xe7d38 0x5733f 0x57552 0x353aa 0x26cf8 0x1BFAD0 0x1c14bf5 0x1c14962 0x1c45bb6 0x1c44f44 0x1c44e1b 0x1bf97e3 0x1bf9668 0x2465c 0x28fd 0x2825)libc++.dylib:终止引发异常(lldb)你没有在你的项目中使用ARC吗?我在我的项目中使用ARC可能是错误的,但我认为没有理由将任何对象强制转换为id。你有两次
{
,一次
}
。这段代码不是问题。我创建了一个新项目,并完全使用了你的代码(只有一个
{
)。它按预期工作。我得到一个带有3个按钮的操作表:浅灰色的“拍照”和“从库中选择”,深灰色的“取消”按钮,标题为“从…选择图像”。你在应用程序中使用了tabBar吗?不是大括号问题。没有tabBar,一个完全干净的单视图项目你有
{
两次,和
}
一次。这个代码不是问题。我创建了一个新项目,并完全使用了你的代码(只有一个
{
)。它按预期工作。我得到了一个带有3个按钮的操作表:浅灰色的“拍照”和“从库中选择”,以及深灰色的“取消”按钮,标题是“从…中选择图像”您是否在应用程序中使用了tabBar?不是大括号问题。没有tabBar,这是一个完全干净的基于单个视图的项目。您可以尝试:
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
。如果出现问题,这可能会解决tabBar的问题。您可以尝试:
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
。如果出现问题,这可能会解决选项卡栏的问题。问题中的代码适用于iPhone、iPhone 3,5“和iPhone 4”(已测试)。问题中的代码适用于iPhone、iPhone 3,5“和iPhone 4”(已测试)请查看我提供的上述链接。这是UIActionSheet的一个示例。请查看我提供的上述链接。这是UIActionSheet的一个示例