- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否可以将 Alert View 委托(delegate)设置为其他 ViewController。原因是因为我打算根据用户按下的警报 View 按钮执行某个操作。
这是我正在尝试做的:-
1] 声明<UIAlertViewDelegate>
在我需要实现 alertView 委托(delegate)方法的 View controller.h 文件中。
2]这是在 AppDelegate 中声明我的 alertView 的方式。
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
alertView = [[UIAlertView alloc]initWithTitle:@"New Message" message:@"Click switch to check out" delegate:rosterListController cancelButtonTitle:@"OK" otherButtonTitles:@"Switch ", nil];
[alertView show];
}
}
3] 现在我想实现 alertView 委托(delegate)方法 clickedButtonAtIndex
在另一个 View Controller 中,但它不会被调用。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
NSLog(@"Cancel button pressed");
}
}
最佳答案
您应该使 AppDelegate 成为 AlertView Delegate,因为它是呈现 Alter View 的 App Delegate。使用随机的不相关的 View Controller 是没有意义的。如果您无论如何都强烈希望这样做,请考虑您的设计和应用程序逻辑有问题。
或者,您可以创建一个新类,它成为委托(delegate)。此类的唯一目的是处理警报 View 事件,并可能在演示者和警报 View 之间传回数据和强制。您可以定义一个协议(protocol),它定义了演示者必须满足的最低 API,以便与委托(delegate)处理程序进行通信。
对于呈现此警报 View 的每个演示者,都有一个委托(delegate)对象的 ivar。当你呈现Alert View时,无论是哪个presenter,创建并初始化delegate对象并将其设置为delegate。当警报 View 将被关闭时,释放委托(delegate)对象。
请注意,委托(delegate)对象可能需要对演示者的引用,以便处理关闭事件。
关于ios - 如何将另一个 ViewController 设置为 AlertView 的委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20344524/
在我的应用程序中,我需要在用户单击警报 View 中的按钮时关闭警报 View 。我在我的应用中尝试了 [alertView dismissWithClickedButtonIndex:-1 anim
我在显示 5 个选项卡的 MainWindow.xib 上添加了一个选项卡栏 Controller ,并在我的应用程序委托(delegate)中具有选项卡栏 Controller 的委托(delega
我想显示嵌套的alertView。我在嵌套alertViews中面临的问题是,当我单击第一个alertView的“添加”按钮时,它显示第二个alertView,在第二个alertView中我有一个文本
如果我在 Controller 上有多个 AlertView,如果所有 AlertView 都分别触发,如何让它只显示最后一个 AlertView?请看下面的代码: override func vie
正如上面的问题所述,我对 iOS 非常陌生;我正在尝试执行这 3 个简单的步骤。 显示提醒 View 进行解析工作 关闭提醒 我正在寻找类似 android 中的东西,即 Pre Execute、do
我最近开始研究 iOS 开发,如果我问的问题太明显,请原谅我。 当我的应用程序的 View 加载时,它会检查某些键的配置,如果这些键没有值,应用程序应显示警报并退出。 首先,我已经实现了 UIAler
我正在定制 keyboard (iOS App Extension) .我有一个 UICollectionView在我的Keyboard Layout , 所以当一个 item已选中 我要显示 mes
我对警报 View 有一个小问题,想法是当应用程序启动时,它会在后台询问应用程序的新数据,因此在收到信息后,如果有新数据,则应显示警报 View 。问题来了,因为 AlertView 只显示在我启动
我首先使用“[UIAlertView alloc] initWithTitle:”来调整大小和自定义带有图像的AlertView,但失败了。 然后我使用以下代码,一切正常(调整了 alertView
我希望用户无法单击 UIAlertView 上的取消按钮,但我仍然希望它在那里,但被遮蔽了。我知道那里有一个 shouldEnableFirstButton 函数,但它不涉及取消按钮。你知道怎么做吗?
这似乎是 iPhone 的白象。我已经尝试了各种方法,甚至是循环,但我无法让它工作。 我有一个加载表格的 View 。然而,我已经进入对象归档,出于开发目的,我想要一个初始的 AlertView,询问
我想在没有按钮的 AlertView 中显示一个事件指示器,我想在事件指示器停止动画时禁用它。 最佳答案 UIAlertView *alert = [[UIAlertView alloc] initW
我刚刚看到无论如何都可以在主屏幕的背景中显示 AlertView。 这是由应用“UP by Jawbone”触发的 有人知道怎么做吗? 最佳答案 这是一条系统消息,因为 UP 尝试使用蓝牙。它不是由应
如何在不使用任何取消按钮的情况下让 alertview 自行消失? 最佳答案 使用这个... -(void)showAlertView { // code for showing your al
我正在尝试创建一个提醒 View ,在点击广告按钮后将一个或多个项目添加到我的表格 View 中。在按下添加按钮时,alertview 应该出现三个文本字段,用于显示项目名称、价格和数量,当按下确定按
我有一个警报 View ,其中添加了一个 uitextfield 作为 subview 。 在我的 uitableview Controller 中,键盘显示正常。 然而,在不同的角度来看,我想做同样
我有一个 UIAlertView,里面有一个 UITextField。我想输入 mail id 并在 UIAlertView 的 ok 按钮中提交,但是 UITextField 在 UIAlert
我有一个委托(delegate),它接收一条消息,以删除该项目作为参数的项目。 我想显示一个确认 AlertView,然后,如果用户按是,我想删除它。 所以,我所拥有的是 被调用的委托(delegat
希望你能帮助我。我如何用 else 语句显示alertView。在我的示例中,我检查文本字段是否为空。当它们为空时,它们将填充用户文本输入。现在,如果所有文本字段都填充了文本,我将显示一个警报 Vie
所以我让警报 View 检测是否存在事件的互联网连接。 这是代码: - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificatio
我是一名优秀的程序员,十分优秀!