UIActionSheet没有在iOS 7 GM上的最后一项显示分隔符

Pun*_*nty 46 iphone uikit uiactionsheet ios ios7

这可能是iOS7上的一个错误.但是最后一个按钮与前一个按钮没有分开UIActionSheet在最后一个按钮上缺少分隔符

从图像中可以看出.使用iOS7 GM在Simulator和设备上都会发生这种情况.其他人都有同样的问题吗?

UIActionSheet *actionSheet = [[UIActionSheet alloc]
               initWithTitle:@"Title"
               delegate:self
               cancelButtonTitle:nil
               destructiveButtonTitle:nil
               otherButtonTitles:@"First", @"Second", @"Third", @"Fourth", nil];
[actionSheet showInView:self.view];
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,代码非常简单.有关如何解决问题的任何想法?或者我可以使用一些第三方库而不是UIActionSheet?

Yid*_*ing 24

我认为ActionSheet 需要一个取消按钮.所以你可以添加取消按钮标题.

另一种方法是:指定actionSheet的cancelButtonIndex.

例如,在您的情况下,您可以在索引4处的otherButtonTitles中添加" Cancel ",然后指定 actionSheet.cancelButtonIndex = 4.

  • 起初我并不认为这是理想的,但我没有意识到,如果你添加一个取消按钮,iPad就足够聪明,不能显示它.(在iOS 6中也是如此.)由于iPhone应该有一个取消按钮,这个解决方案非常有效. (4认同)

tee*_*bot 8

我找到了一种方法,可以用最简单的方式使它在iPhone和iPad上运行:

  1. 仅使用标题初始化UIActionSheet
  2. 添加按钮
  3. 最后添加一个"CANCEL"按钮
  4. 将CancelButtonIndex设置为最后一个索引

我假设丢失的分隔符是由首先添加或通过init添加取消按钮时不被识别为单独的情况引起的.


Chr*_*ris 6

我发现初始化后添加一个带空字符串的取消按钮.取消按钮不会显示,分隔符显示.

[sheet addButtonWithTitle: @""];
[sheet setCancelButtonIndex: sheet.numberOfButtons - 1];
Run Code Online (Sandbox Code Playgroud)

但这仅适用于iPad.在iPhone上,显示一个空取消按钮,但我发现了一个hacky解决方法,使其工作.除上述内容外,在willPresentActionSheet此处添加以下代码:

NSInteger offset = 55;
CGRect superFrame = actionSheet.superview.frame;
superFrame.origin.y += offset;
[actionSheet.superview setFrame: superFrame];

// hide underlay that gets shifted with the superview
[(UIView*)[[actionSheet.superview subviews] objectAtIndex: 0] removeFromSuperview];

// create new underlay
CGRect underlayFrame = CGRectMake(0, -offset, superFrame.size.width, superFrame.size.height);
UIView* underlay = [[UIView alloc] initWithFrame: underlayFrame];
underlay.alpha = 0.0f;
[underlay setBackgroundColor: [UIColor colorWithWhite: 0.0f alpha: 0.4f]];
[actionSheet.superview insertSubview: underlay atIndex: 0];

// simulate fade in
[UIView animateWithDuration: 0.3f animations:^{
    underlay.alpha = 1.0f;
}];
Run Code Online (Sandbox Code Playgroud)

这会向下移动工作表以隐藏屏幕上的取消按钮

  • 它**在iPad上运行完美**,谢谢! (2认同)

aha*_*aha 5

最简单的解决方法是传递@""给取消按钮标题而不是nil分配期间.

UIActionSheet *actionSheet = [[UIActionSheet alloc]
               initWithTitle:@"Title"
               delegate:self
               cancelButtonTitle:@"" // change is here
               destructiveButtonTitle:nil
               otherButtonTitles:@"First", @"Second", @"Third", @"Fourth", nil];
[actionSheet showInView:self.view];
Run Code Online (Sandbox Code Playgroud)


小智 1

如果您有取消按钮,则会显示最后一行。这是我现在使用的临时修复。如果您不想显示取消按钮,不知道有什么解决方案