use*_*780 14 alert objective-c uialertview ios ios8
在iOS 8上运行我们的应用程序时,我遇到了与UIAlertView相关的问题.我正在显示标题为nil的警报.它在iOS 7中运行良好,但现在UI看起来很奇怪.
我在这里附上截图.
我找到的一个解决方案是,当我提供空字符串@""时,它看起来没问题.见下面的截图.但我不确定我提到的问题是否是测试版iOS 8版本中的错误,或者是否还有其他更好的解决方案.即使使用该解决方案,它也不像iOS 7中那样精确.

iOS 7 - 显示标题为nil的警报视图.截图在这里.

Mik*_*e S 11
我最接近iOS 8的方法是设置标题而不是消息:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location field required." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
Run Code Online (Sandbox Code Playgroud)

但是应该注意的是,UIAlertView在iOS 8中已弃用,如果你要为iOS 7和iOS 8使用单独的代码路径,你应该使用UIAlertController:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Location field required." message:nil preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]];
[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
我用两种方法得到了相同的结果.
这一直是我使用的最佳实践initWithTitle:@""的UIAlertView,UIActionSheet因为我是在我使用时候,那个时候面临的设计问题,因为iOS 6中initWithTitle:nil.我试图找回来,我找不到它究竟是什么原因.
从你在iOS 8上的屏幕截图中,我认为UIAlertView for iOS 8 的视图层次结构发生了变化.我认为Auto layout可能会在视图层次上实现,你可以看到messageLabel跳转到titleLabel.
我无法确定,因为UIAlertView的视图层次结构是私有的.
UIAlertView类旨在按原样使用,不支持子类化.此类的视图层次结构是私有的,不得修改.
请参阅:https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
但是,我使用的代码: -
NSLog(@"%@",[self.alertView description]);
Run Code Online (Sandbox Code Playgroud)
iOS 7.1上的结果:
<UIAlertView: 0x7fb3c05535b0; frame = (18 263; 284 62); opaque = NO; layer = <CALayer: 0x7fb3c0519810>>
Run Code Online (Sandbox Code Playgroud)
iOS 8.0上的结果:
<UIAlertView: 0x7bf64840; frame = (0 0; 0 0); layer = <CALayer: 0x7bf648f0>>
Run Code Online (Sandbox Code Playgroud)
我不知道为什么iOS 8的UIAlertView框架是(0 0; 0 0);
就像迈克说的那样,我认为你应该学会使用UIAlertControlleriOS 8.
| 归档时间: |
|
| 查看次数: |
5524 次 |
| 最近记录: |