Я новичок в iphone.i, делая приложение напоминания в своем проекте. я хочу получить входные значения, такие как название и данные напоминания & Время от uiactionsheet.i создало datepicker и uitextfield в листе действий. Actionsheet появляется с textfield.when я нажал на текстовое поле, клавиатура появляется, но не работает means..when я набралась они не видны в текстовом полеКак работать с UITextFields внутри UIActionsheet?
-(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
}
Я не уверен, почему он не принимает ввод с клавиатуры. Какие-либо предложения?
Это злоупотребление 'UIActionSheet'. Это не цель. Не используйте стандартные компоненты пользовательского интерфейса так, чтобы они не были разработаны. Что произойдет, когда Apple полностью изменит поведение 'UIActionSheet' или будет выглядеть в будущей версии iOS? Создайте собственное пользовательское представление для отображения того, что вам нужно. – rmaddy
, но вам нужно поставить UITextField в UIActionSheet? это очень просто и красиво положить в UIAlertView. – iPatel
Почему вы не используете Alert вместо UIActionsheet ..? –