检测哪个 UIAlertView 被点击
我需要在加载应用程序时弹出警报...我称之为“完成启动”.. 单击“确定”按钮后需要显示另一条警报消息,我使用 clickedButtonAtIndex...
现在,当我单击“确定”按钮时,它会一次又一次地调用...警报视图..
我只需要调用一次...该怎么办?
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
viewControllersList = [[NSMutableArray alloc] init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Alow this app to use your GPS location"
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
NSLog(@"NO");
}
else {
NSLog(@"Yes");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Do you want's to receive Push messages."
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];
}
}
@提前致谢。
i need to pop up alert when my application loaded... I called it didfinished launching..
after clicking ok button need to show another alert message i use clickedButtonAtIndex...
Now when I clicked the ok button its calling again and again.. the alertview..
I need to call only once... what to do?
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
viewControllersList = [[NSMutableArray alloc] init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Alow this app to use your GPS location"
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
NSLog(@"NO");
}
else {
NSLog(@"Yes");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Do you want's to receive Push messages."
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];
}
}
@thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在第二个alertView中设置
delegate:nil
我是说
set
delegate:nil
in second alertViewI mean
您还可以向 AlertView 添加一个标签,并稍后在 clickedButtonAtIndex 方法上检查该标签,
然后
You can also add a tag to your AlertView and te check the tag later on the clickedButtonAtIndex method
then
定义每个 UIAlertView 并在委托中查找要响应的警报:
Define each UIAlertView and in the delegate look for which Alert to respond to:
如果您想要接收位置,只需请求,系统就会自动为您显示消息。请按照以下示例操作:
}
http://developer.apple.com/library/ios/#samplecode/LocateMe/Listings/Classes_AppDelegate_m.html%23//apple_ref/doc/uid/DTS40007801-Classes_AppDelegate_m-DontLinkElementID_4
相同用于推送通知。
If what you want is to receive the location, just request it and the system will automatically show the message for you. Follow this example:
}
http://developer.apple.com/library/ios/#samplecode/LocateMe/Listings/Classes_AppDelegate_m.html%23//apple_ref/doc/uid/DTS40007801-Classes_AppDelegate_m-DontLinkElementID_4
Same for push notifications.
虽然你已经有了很多实现解决方案......但我认为更好的做法是为每个 AlertView 分配一个标签,并在检测点击的按钮之前检查调用 AlertView 的标签。希望这会有所帮助。
@Gerard:虽然位置管理器和推送通知服务都会引发系统生成的消息,但用户可以检查这些消息,以免再次显示。因此,更好的 HIG 投诉方法是在需要推送或位置管理器时应用程序生成消息。
though u got many implementation solutions already ...but i think better practice would be to assign a tag to each of your AlertView and before detecting the button tapped check the tag of invoking AlertView.Hope this helps.
@Gerard:Though both location manager and push notification service raise system generated messages ,these can be checked off by users not to be shown again.So better HIG complaint method is application generating message whenever push or location manager are required.