在我的选择器视图中,我有一个“自定义”选项,该选项应弹出UIAlertView以供用户输入新值,该值将保存在选择器的plist源中以供将来参考。正在重复调用xxxEditingDidBegin(永无止境)。
我推测它是因为我的UIAlertView触发了选择器关闭。
我该怎么做?
- (IBAction)serviceTypeFieldEditingDidEnd:(UITextField *)sender
{
UIPickerView *picker = [sender.inputView.subviews objectAtIndex:0];
NSString *selText = [serviceTypeArray objectAtIndex: [picker selectedRowInComponent:0]];
sender.text = selText;
if (NSOrderedSame==[selText compare:@"Custom"])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Custom Role"
message:@"Enter Role Title"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
}
答案 0 :(得分:0)
实施类似
的方法- (IBAction)doSelectDate:(UIDatePicker *)sender
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Hi" message:@"AlertView is shwoing" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
并将上述方法与UIPickerView的ValueChanged事件连接;
答案 1 :(得分:0)
我像这样修理了
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *rowString = [serviceTypeArray objectAtIndex:row];
if ([rowString compare:@"Custom"] == NSOrderedSame)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Custom Role"
message:@"Enter Role Title"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
else
{
_serviceType.text = rowString;
}
}