iOS 8 今日小部件 - UIAlertView

3

能否在今日小部件中添加类似于UIAlertView的东西?我在小部件中添加了一个IBAction和UIAlertView,但是没有任何反应。

还有,是否可以制作更大的小部件?我在Size-Inspector中更改了高度,但完全没有任何效果。


UIAlertViewUIActionSheet已被弃用,您现在需要使用UIAlertController - Popeye
你有例子吗?它不起作用 :( - user2531284
3个回答

2
短答案是不行的,你不能在今日小部件中显示警报。 UIAlertControllers 是以模态方式呈现的,而你的小部件没有访问整个屏幕的权限。它最多只能显示大约3/4的屏幕高度。

0

以下是一些基本的 Swift 代码(适用于未来的项目):

let alertController = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)
self.presentViewController(alertController, animated: true, completion: nil)

UIAlertControllers以全屏幕方式呈现,无法在今天的小部件中使用。 - Christopher Pickslay

-2

在iOS8上,您需要使用UIAlertController,参考链接在这里

例如:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertView" message:@"I am an AlertView" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction * action) {
                                                          [alert dismissViewControllerAnimated:YES completion:nil];
                                                      }];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];

1
实际上,如果您尝试在今天的应用扩展小部件中执行此操作,则会在运行时收到以下消息: 2014-08-25 16:42:21.994 LauncherWidget[76137:2316933] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason:'特性不可用于类型为com.apple.widget-extension的扩展程序' - Greg G
抱歉,这个在测试版中是可以运行的,但现在已经无法工作了。 - GondyB

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接