【发布时间】:2012-07-05 15:04:22
【问题描述】:
像java中的JOptionPane, 当用户做某事时。 我要求确认,例如, 你确定要删除文件吗??或无论如何。 用户确认 然后我检测到用户在两个按钮之间选择了什么 然后我根据用户的选择做一些事情
在目标 c 中有这样的东西吗? 链接请和一些指导方针
谢谢大家
【问题讨论】:
标签: iphone objective-c xcode ios5
像java中的JOptionPane, 当用户做某事时。 我要求确认,例如, 你确定要删除文件吗??或无论如何。 用户确认 然后我检测到用户在两个按钮之间选择了什么 然后我根据用户的选择做一些事情
在目标 c 中有这样的东西吗? 链接请和一些指导方针
谢谢大家
【问题讨论】:
标签: iphone objective-c xcode ios5
您正在寻找 UIAlertView 控制器。
【讨论】:
我相信你想要UIActionSheet,这是苹果推荐给用户的选择:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Some Message" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"button To Destroy or nil" otherButtonTitles:@"Choice 1", @"Choice 2", @"Choice 3", nil];
【讨论】:
你要做的是检查otherButtonTitles:下的哪个按钮被点击
类似这样的:
UIAlertView *yourAlert = [[UIAlertView alloc] initWithTitle:@"Your title" message:@"Some String" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Confirm",nil];
[yourAlert show];
记得将委托设置为 self。
然后:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (buttonIndex == 0){ //'Dismissing' code here } if (buttonIndex == 1){ //Detecting whatever was under otherButtonTitles: //Right now it's checking if the user clicked "Confirm" -> So here you can put whatever you need NSLog(@"You clicked Confirm"); }}
在条件下,您正在检查用户正在单击哪个按钮。
【讨论】: