相关疑难解决方法(0)

UIAlertView/UIAlertController兼容iOS 7和iOS 8

我正在使用Swift编写应用程序,我需要显示警报.该应用必须兼容iOS 7和iOS 8.由于UIAlertView已被替换UIAlertController,如何在UIAlertController不检查系统版本的情况下检查是否可用?我听说Apple建议我们不要检查设备的系统版本,以确定API的可用性.

这就是我在iOS 8中使用的,但是在iOS 7上用" dyld: Symbol not found: _OBJC_CLASS_$_UIAlertAction" 崩溃了:

let alert = UIAlertController(title: "Error", message: message, preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
alert.addAction(cancelAction)
presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

如果我使用UIAlertView for iOS 8,我收到此警告: Warning: Attempt to dismiss from view controller <_UIAlertShimPresentingViewController: 0x7bf72d60> while a presentation or dismiss is in progress!

uialertview ios swift uialertcontroller

57
推荐指数
5
解决办法
5万
查看次数

键盘失去隐藏能力"如果我使用UIAlertView"

我正在编写一些iPad应用程序,并开始出现奇怪的效果.

我使用导航栏,因此我可以在我的视图中自由导航.无论如何,在其中一个内部视图中,我提供了检查用户是否真的想通过警报视图返回主视图的可能性(Just a Yes/no按钮).一旦用户确认他想要返回,然后我"手动"弹出视图,然后我导航到键盘隐藏的主视图.

但是,虚拟键盘的行为很奇怪.在"内部视图"内部,键盘在90%的时间内都可见(这是正常的,周围有很多UITextField).每当我想要隐藏它时,我该怎么做才能隐藏它?我把这样的东西放在"main viewWillAppear"中:

[self.view endEditing:YES];
Run Code Online (Sandbox Code Playgroud)

显然它隐藏了键盘,当我这样做时:

[[self navigationController] popToRootViewControllerAnimated:YES]; 
Run Code Online (Sandbox Code Playgroud)

iPad导航回来,然后键盘消失.没什么大不了的(第一次).

但后来我决定重新进入相​​同的视图,所以键盘出现,我做了一些奇特的东西.然后我决定中止(使用我的按钮),我再次显示相同的警报视图,我确认我想回到主视图(就像之前一样).代码是相同的,但在主视图中,:

[self.view endEditing:YES];
Run Code Online (Sandbox Code Playgroud)

对于整个会话,我已经失去了通过我的应用程序内的代码ANYWHERE关闭键盘的能力.

为什么我知道UIAlertView有事可做?因为如果我更改了我的"中止按钮"中的代码:

alertViewQuestionType=ALERT_ABANDON_TEST;
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"" message:NSLocalizedStringFromTable (@"STR_ABANDON_TEST_WARNING", @"ui_strings", @"") delegate:self cancelButtonTitle:NSLocalizedStringFromTable (@"STR_CANCEL", @"ui_strings", @"") otherButtonTitles:nil] autorelease];
[alert addButtonWithTitle:NSLocalizedStringFromTable (@"STR_ABANDON", @"ui_strings", @"")];
[alert show];
Run Code Online (Sandbox Code Playgroud)

对此:

[[self navigationController] popToRootViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)

(也就是说,没有确认用户,用户只需按下中止按钮就可以导航回来),然后当主视图到达"viewWillAppear"功能时,隐藏键盘代码就可以了.不仅是时间,而是所有时间,直到我的应用程序会话结束.

我不知道我的问题是否100%明确,但如果有人认为他可以为这个错误提供一些启示,我会非常乐意在这里添加一些额外的代码......

问候!

iphone keyboard uialertview ios

4
推荐指数
1
解决办法
1941
查看次数

标签 统计

ios ×2

uialertview ×2

iphone ×1

keyboard ×1

swift ×1

uialertcontroller ×1