【发布时间】:2013-12-03 06:41:09
【问题描述】:
我想知道是否可以将警报视图委托设置为其他视图控制器。 原因是因为我打算根据用户按下的警报视图按钮来实现某个动作。
这是我想要做的:-
1] 在需要实现 alertView 委托方法的视图 controller.h 文件中声明 <UIAlertViewDelegate>。
2]这就是我的 alertView 在 AppDelegate 中的声明方式。
- (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] 现在我想在另一个 View Controller 中实现 alertView 委托方法 clickedButtonAtIndex,但它没有被调用。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
NSLog(@"Cancel button pressed");
}
}
【问题讨论】:
-
rosterListController 是否存在或者它不存在?
-
ohk....名册列表控制器为零....
-
好吧,为了让某人为你做某事,那个人需要存在,不是吗?因此,如果您希望您的 viewController 处理委托方法,则需要在将其设置为委托之前创建它 (alloc, init)。
标签: ios uiviewcontroller delegates uialertview