我是 iphone 的新手。我正在为我的项目做提醒应用程序。我想从 uiactionsheet 获取提醒标题和数据和时间等输入值。我在 actionsheet 中创建了 datepicker 和 uitextfield。操作表与文本字段一起出现。当我单击文本字段时,键盘出现但无法正常工作。当我输入时,它们在文本字段中不可见
-(void)btnSetRemainderTapped:(id)sender
{
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Select reminder date and time"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Save"
otherButtonTitles:nil,nil];
menu.tag =10;
[menu showInView:self.view];
menu.userInteractionEnabled=YES;
UITextField *txtReminderTitle= [[UITextField alloc] initWithFrame:CGRectMake(20.0, 180, 280.0, 40.0)];
[txtReminderTitle setTag:99];
[txtReminderTitle setBackgroundColor:[UIColor whiteColor]];
[txtReminderTitle setFont:[UIFont boldSystemFontOfSize:17]];
[txtReminderTitle setBorderStyle:UITextBorderStyleNone];
[txtReminderTitle setTextAlignment:UITextAlignmentCenter];
txtReminderTitle.borderStyle = UITextBorderStyleRoundedRect;
txtReminderTitle.keyboardType = UIKeyboardTypeDefault;
txtReminderTitle.returnKeyType = UIReturnKeyDone;
txtReminderTitle.delegate =self;
[menu addSubview:txtReminderTitle];
UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeDateAndTime;
pickerView.tag =9999;
[menu addSubview:pickerView];
CGRect menuRect = menu.frame;
NSInteger orgHeight = menuRect.size.height;
menuRect.origin.y -= 270; //height of picker
menuRect.size.height = orgHeight+270;
menu.frame = menuRect;
CGRect pickerRect = CGRectMake(20, 250, 280, 200);
pickerView.frame = pickerRect;
}
-(void) actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
UIDatePicker *datePicker = (UIDatePicker *)[actionSheet viewWithTag:9999];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterLongStyle;
[df setTimeStyle:NSDateFormatterShortStyle];
UITextField * txtReminderTitle = (UITextField *)[actionSheet viewWithTag:99];
NSLog(@"%@",txtReminderTitle.text); //it print null value
}
我不确定为什么它不接受来自键盘的输入。有什么建议么?