Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在UIActionsheet中使用UITextFields?_Iphone_Ios_Uiactionsheet - Fatal编程技术网

Iphone 如何在UIActionsheet中使用UITextFields?

Iphone 如何在UIActionsheet中使用UITextFields?,iphone,ios,uiactionsheet,Iphone,Ios,Uiactionsheet,我是iphone新手。我正在为我的项目做提醒应用程序。我想从uiactionsheet中获取提醒标题、数据和时间等输入值。我已经在actionsheet中创建了datepicker和uitextfield。操作表显示为textfield。当我单击textfield时,键盘显示但不工作意味着..当我键入时,它们在textfield中不可见 -(void)btnSetRemainderTapped:(id)sender { UIActionSheet *menu = [[UIActionSheet

我是iphone新手。我正在为我的项目做提醒应用程序。我想从uiactionsheet中获取提醒标题、数据和时间等输入值。我已经在actionsheet中创建了datepicker和uitextfield。操作表显示为textfield。当我单击textfield时,键盘显示但不工作意味着..当我键入时,它们在textfield中不可见

-(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;
}


我不知道为什么它不接受键盘的输入。有什么建议吗?

使用自定义UIActionSheet。您喜欢以下内容吗
1) 添加新的UIViewController
2) 声明一个UITextField

@interface ViewController  
{
            UITextField *TextField;

    }
3) 添加操作表和文本字段的委托

@interface ViewController : UIViewController <UIActionSheetDelegate, UITextFieldDelegate> {

        UITextField *TextField;

    }
@界面ViewController:UIViewController{
UITextField*TextField;
}
4) 现在实现方法


查看我在

上看到的此链接我发现,当您将
UITextField
添加到
UIActionSheet
时,
UITextField
仍保留在
UIActionSheet
下。因此,您需要将
UITextField
置于
UIActionSheet
上方,这样做
[菜单添加子视图:TXT提醒]不适用于
UITextField
输入任何文本

使用以下代码添加
UITextField

UIWindow *appWindow = [UIApplication sharedApplication].keyWindow;
[appWindow insertSubview:txtReminderTitle aboveSubview:menu];

只需更改如何添加
UITextField

这是对
UIActionSheet
的滥用。这不是它的目的。不要以非设计的方式使用标准UI组件。如果苹果完全改变了iOS未来版本中的
UIActionSheet
的工作方式或外观,会发生什么?创建您自己的自定义视图以显示所需内容。但您需要在UIActionSheet中放置UITextField吗??将其放在UIAlertView中既简单又美观。为什么不使用Alert而不是UIActionsheet?@iPatel他还需要一个
UIDatePicker
。你不能把它放在
UIAlertView
中。我已经检查了alertView和ViewController是否正常工作,但我怀疑我们能否在uiactionsheet中实现textfield?@Ravindhiran发布的链接中接受的答案就是我所说的。它是一个自定义类,无需使用
UIActionSheet
即可执行您想要的操作。请考虑使用该代码作为解决方案的基础。K,谢谢你,你怀疑他为什么要执行@接口TalalVIEW控制器:UIViewController,UIAcon SueTeCuto需要什么?他用而不是uiview@Ravindhiran没有任何理由认为自定义视图控制器应该遵守
UIActionSheetDelegate
。这应该被删除。
UIWindow *appWindow = [UIApplication sharedApplication].keyWindow;
[appWindow insertSubview:txtReminderTitle aboveSubview:menu];