我有一个UIPicker,当选择一行时触发UIAlert。在UIPicker“完成”按钮被按下并且UIPicker关闭后,我正在尝试弹出警报。当选择行时,警报会触发。因此,当有人滚动选择器中的每一行时,UIAlert会不断弹出。
感谢您的帮助
这是'完成'按钮代码:
-(IBAction)done{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
pickerView.transform = transform;
[UIView commitAnimations];
}
这是一个选择器UIAlert代码的示例,显示“case 0”以及警告消息:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
UIColor *newColor;
switch (row) {
case 0:
newColor = [UIColor yellowColor];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[alert show];
[alert release];
myLabel.text = @"sometext";
break;
}
答案 0 :(得分:2)
//Init the done button with an action to show an alert
// and the target as self
self.myBarBtnItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemDefault target:self action:@selector(showAlert:)]
然后你的行动:
// Show the alert with the currently selected row index of the picker
- (void)showAlert:(id)sender {
NSUInteger selectedIndex = [myPickerView selectedRowInComponent:0];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat@"Row %f selected!", selectedIndex + 1] message:[NSString stringWithFormat:@"Row %d / %d selected.", selectedIndex + 1, [self pickerView:myPickerView numberOfRowsInComponent:0]] autorelease];
[alert show];
}
答案 1 :(得分:1)
-(IBAction)done{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[alert show];
[alert release];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
pickerView.transform = transform;
[UIView commitAnimations];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
UIColor *newColor;
switch (row) {
case 0:
newColor = [UIColor yellowColor];
myLabel.text = @"sometext";
break;
}
}
答案 2 :(得分:0)