- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有三个TextFields regionText
sectionText
distributionText
。如果我单击“第一个文本字段” regionText
,则应该显示PickerView regionPicker
和Array值regionArray
。如果我没有选择sectionText
中的值就单击distributionText
或regionText
,则应显示警报消息。
然后,基于regionText
值
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
//static Array for RegionPicker
NSArray *regionArray = [[NSArray alloc]initWithObjects:@"Chennai-south",@"Chennai-north",@"Villupuram", nil];
//static Array for SectionPicker
NSArray *chennaiSouthArray = [[NSArray alloc]initWithObjects:@"A",@"B",@"C", nil];
NSArray *chennaiNorthArray = [[NSArray alloc]initWithObjects:@"D",@"E",@"F", nil];
NSArray *villupuramArray = [[NSArray alloc]initWithObjects:@"D",@"E",@"F", nil];
//static Array for DistributionPicker
NSArray *aArray = [[NSArray alloc]initWithObjects:@"a",@"b", nil];
NSArray *bArray = [[NSArray alloc]initWithObjects:@"c",@"d", nil];
NSArray *cArray = [[NSArray alloc]initWithObjects:@"e",@"f", nil];
NSArray *dArray = [[NSArray alloc]initWithObjects:@"g",@"h", nil];
NSArray *eArray = [[NSArray alloc]initWithObjects:@"i",@"j", nil];
//viewForPicker
_viewForPicker = [[UIView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width,260)];
_viewForPicker.backgroundColor = [UIColor blackColor];
[self.view addSubview:_viewForPicker];
//regionPickerView
_regionPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 216)];
_regionPicker.delegate = self;
_regionPicker.dataSource = self;
_regionPicker.showsSelectionIndicator = YES;
[_regionPicker setBackgroundColor:[UIColor lightGrayColor]];
[_viewForPicker addSubview:_regionPicker];
//ToolBar
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,44)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered target:self action:@selector(hidePickerView:)];
toolBar.items = @[barButtonDone];
barButtonDone.tintColor=[UIColor lightTextColor];
[barButtonDone setEnabled:YES];
[_viewForPicker addSubview:toolBar];
//SettingLabels
[self setView];
}
-(void)hidePickerView:(id)sender
{
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
_viewForPicker.frame = CGRectMake(0, self.view.frame.size.height, 320, 260);
} completion:^(BOOL finished){
}];
}
-(void)setView
{
//regionLabel
UILabel *regionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+30, 60, 25)];
[regionLabel setText:@"Region"];
[self.view addSubview:regionLabel];
//regionText
UITextField *regionText = [[UITextField alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+30, 150, 25)];
[regionText setBorderStyle:UITextBorderStyleRoundedRect];
[regionText setPlaceholder:@"selectRegion"];
[regionText setTag:0];
[regionText setDelegate:self];
[self.view addSubview:regionText];
//sectionLabel
UILabel *sectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+120, 60, 25)];
[sectionLabel setText:@"Section"];
[self.view addSubview:sectionLabel];
//sectionText
UITextField *sectionText = [[UITextField alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+120, 150, 25)];
[sectionText setBorderStyle:UITextBorderStyleRoundedRect];
[sectionText setPlaceholder:@"selectSection"];
[sectionText setTag:1];
[sectionText setDelegate:self];
[self.view addSubview:sectionText];
//distributionLabel
UILabel *distributionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+210, 90, 25)];
[distributionLabel setText:@"Distribution"];
[self.view addSubview:distributionLabel];
//distributionText
UITextField *distributionText = [[UITextField alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+210, 150, 25)];
[distributionText setBorderStyle:UITextBorderStyleRoundedRect];
[distributionText setPlaceholder:@"selectDistribution"];
[distributionText setTag:2];
[distributionText setDelegate:self];
[self.view addSubview:distributionText];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Show UIPickerView
if (textField isEqual:@"regionText")
{
NSLog(@"Entering Textfield Begin");
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
_viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
}
completion:^(BOOL finished){
}];
}
elseif(textField isEqual:@"sectionText")
{
//What i have to Write in This.Please Update.
}
else
{
//What i have to Write in This.Please Update.
}
return NO;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
{
if([pickerView isEqual:@"regionPicker"])
return [regionArray count];
elseif([pickerView isEqual:@"regionPicker"])
{
//What i have to write.Pls update.
}
else
{
//What i have to write.Pls update.
}
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//What i have to write.Pls update.
}
最佳答案
这是经过测试的更新代码:
首先在.h文件中声明:
UIView *_viewForPicker;
UIPickerView *_regionPicker;
NSArray *regionArray;
NSArray *chennaiSouthArray;
NSArray *chennaiNorthArray;
NSArray *villupuramArray;
int selectionVal;
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
//static Array for RegionPicker
regionArray = [[NSArray alloc] initWithObjects:@"Chennai-south",@"Chennai-north",@"Villupuram", nil];
//static Array for SectionPicker
chennaiSouthArray = [[NSArray alloc]initWithObjects:@"A",@"B",@"C", nil];
chennaiNorthArray = [[NSArray alloc]initWithObjects:@"D",@"E",@"F", nil];
villupuramArray = [[NSArray alloc]initWithObjects:@"D",@"E",@"F", nil];
//static Array for DistributionPicker
NSArray *aArray = [[NSArray alloc]initWithObjects:@"a",@"b", nil];
NSArray *bArray = [[NSArray alloc]initWithObjects:@"c",@"d", nil];
NSArray *cArray = [[NSArray alloc]initWithObjects:@"e",@"f", nil];
NSArray *dArray = [[NSArray alloc]initWithObjects:@"g",@"h", nil];
NSArray *eArray = [[NSArray alloc]initWithObjects:@"i",@"j", nil];
//viewForPicker
_viewForPicker = [[UIView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width,260)];
_viewForPicker.backgroundColor = [UIColor blackColor];
[self.view addSubview:_viewForPicker];
//regionPickerView
_regionPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 216)];
_regionPicker.delegate = self;
_regionPicker.dataSource = self;
_regionPicker.showsSelectionIndicator = YES;
[_regionPicker setBackgroundColor:[UIColor lightGrayColor]];
[_viewForPicker addSubview:_regionPicker];
//ToolBar
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,44)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(hidePickerView:)];
toolBar.items = @[barButtonDone];
barButtonDone.tintColor=[UIColor lightTextColor];
[barButtonDone setEnabled:YES];
[_viewForPicker addSubview:toolBar];
//SettingLabels
[self setView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
-(void)hidePickerView:(id)sender {
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
_viewForPicker.frame = CGRectMake(0, self.view.frame.size.height, 320, 260);
} completion:^(BOOL finished){
}];
}
-(void)setView {
//regionLabel
UILabel *regionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+30, 60, 25)];
[regionLabel setText:@"Region"];
[self.view addSubview:regionLabel];
//regionText
UITextField *regionText = [[UITextField alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+30, 150, 25)];
[regionText setBorderStyle:UITextBorderStyleRoundedRect];
[regionText setPlaceholder:@"selectRegion"];
[regionText setTag:51];
[regionText setDelegate:self];
[self.view addSubview:regionText];
//sectionLabel
UILabel *sectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+120, 60, 25)];
[sectionLabel setText:@"Section"];
[self.view addSubview:sectionLabel];
//sectionText
UITextField *sectionText = [[UITextField alloc] initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+120, 150, 25)];
[sectionText setBorderStyle:UITextBorderStyleRoundedRect];
[sectionText setPlaceholder:@"selectSection"];
[sectionText setTag:52];
[sectionText setDelegate:self];
[self.view addSubview:sectionText];
//distributionLabel
UILabel *distributionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+210, 90, 25)];
[distributionLabel setText:@"Distribution"];
[self.view addSubview:distributionLabel];
//distributionText
UITextField *distributionText = [[UITextField alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+210, 150, 25)];
[distributionText setBorderStyle:UITextBorderStyleRoundedRect];
[distributionText setPlaceholder:@"selectDistribution"];
[distributionText setTag:53];
[distributionText setDelegate:self];
[self.view addSubview:distributionText];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Show UIPickerView
if (textField.tag == 51){
NSLog(@"Entering Textfield Begin");
selectionVal = 1;
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
_viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
}completion:^(BOOL finished){}];
}else if(textField.tag == 52){
if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@""]) {
[[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Set Region First" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] show];
}else {
selectionVal = 2;
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
_viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
}completion:^(BOOL finished){}];
}
}else if (textField.tag == 53){
if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@""]) {
[[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Set Region First" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] show];
}else{
selectionVal = 3;
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
_viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
}completion:^(BOOL finished){}];
}
}
[_regionPicker reloadAllComponents];
return NO;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component{
if(selectionVal == 1){
return [regionArray count];
}else if(selectionVal == 2){
if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-south"]) {
return chennaiSouthArray.count;
}else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-north"]){
return chennaiNorthArray.count;
}else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Villupuram"]){
return villupuramArray.count;
}
}else if(selectionVal == 3){
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if(selectionVal == 1){
return [regionArray objectAtIndex:row];
}else if(selectionVal == 2){
if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-south"]) {
return [chennaiSouthArray objectAtIndex:row];
}else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-north"]){
return [chennaiNorthArray objectAtIndex:row];
}else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Villupuram"]){
return [villupuramArray objectAtIndex:row];
}
}
return @"test";
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if(selectionVal == 1){
[(UITextField*)[self.view viewWithTag:51] setText:[regionArray objectAtIndex:row]];
}else if(selectionVal == 2){
if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-south"]) {
[(UITextField*)[self.view viewWithTag:52] setText:[chennaiSouthArray objectAtIndex:row]];
}else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-north"]){
[(UITextField*)[self.view viewWithTag:52] setText:[chennaiNorthArray objectAtIndex:row]];
}else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Villupuram"]){
[(UITextField*)[self.view viewWithTag:53] setText:[villupuramArray objectAtIndex:row]];
}
}
}
关于ios - 如何在iOS中使用TextField显示基于先前PickerView的PickerView值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34926201/
我正在开发转换器应用程序。在 iOS 中,我们没有下拉菜单之类的东西。对于一两次转换,这不是问题。但是对于相同类型的多次转换(比如时间:年到月、日、小时、分钟和秒),我们也有相反的转换。它使 UIVi
目前我的 SwiftUI 的光标/插入符号 TextField是蓝色的。是否有用于光标颜色或解决方法的 API? 最佳答案 试了一下, .accentColor 诀窍。 TextField(" Ent
我需要有关此功能的帮助。当我在文本字段中输入文本时,我需要您在我输入另一个文本字段时验证该文本。 这是我的代码 class _ProfileState extends State {
所以在 swift 3 中,我只想遍历 textField outlet 集合,如果 textField.text = "",则对其进行处理。我已经完成了以下操作,但我相信应该有一个更优雅的解决方案,
我正在尝试: 使 TextField 的 trailingIcon 仅在用户输入空格以外的文本时才可见。 稍后当用户单击 trailingIcon 时,TextField 中的文本应该被清除并且 tr
我目前正在尝试实现一个 TextField,它应该根据文本字段的状态(未聚焦、聚焦、错误)更改背景颜色。 我试图通过使用仅管理是否选择了 TextField 的列表来实现此目的。我使用 Gesture
我目前正在我的应用程序中构建一些基本的表单功能,并且在点击另一个 TextField 或在编辑模式下按“完成”时,我遇到了 TextFields 没有更改相关绑定(bind)变量中的值的问题。
我想要一个如下所示的文本字段: 文本字段。文本域 。文本域。文本字段 并在文本字段中仅输入数字。你能帮我吗? :) 最佳答案 您不需要父文本字段来充当 4 个文本字段的容器。将 4 个文本字段放置在面
你好,占位符文本和用户输入的文本从我的文本字段中间开始。我将文本字段设置为屏幕高度的 30%,所以我不能简单地缩小文本字段。如何让文本从左上角开始? 最佳答案 你想要做的是水平和垂直对齐,如下所示:
我遇到了一些奇怪的问题,如果您点击其中一个 TextField,它总是会被清除。 class MyEditText extends StatefulWidget { static String t
我在实现 TextField 时遇到了一些困难。更具体地说,我尝试使用 Controller 清除按钮的 onPress 方法上的 TextField。 controller.clear() 从 Te
有没有一种方法可以让当用户在一个文本字段和另一个文本字段(例如 1 和 1)中输入值时,第三个文本字段立即计算总和并显示它无需向 GUI 添加按钮? 最佳答案 向您的 TextField 添加一个文档
使用 ABCPDF 添加 TextField 相当简单: public FormField AddTextField(string inRect, string inName, string inTe
有两个文本字段(具有自动完成功能): Customer: Store: 如您所见,最初我禁用了第二个文本字段。我想要的是当用户完成从客户文本框中选择项目时,应该启用商店文本框。这是我尝试过
假设我有一个社交网络(例如: http://www.icloud.com/ )。该网站上有 2 个文本字段:电子邮件、密码。 我想为该网站制作一个应用程序,您可以直接从该应用程序登录。在应用程序上,我
在我的添加联系人页面中,正在验证我的电子邮件文本字段、电话号码字段等。并在单击所有其他文本字段时检查有效电子邮件。因此,当我单击电话号码字段时,它将检查电子邮件有效性并在电子邮件无效时显示警报 Vie
使用 TextField View 时,我的 SwiftUI 项目出现奇怪的行为。 使用以下代码,TextField textContentType 设置为 nil(或 .none,或 UITextC
我有一个 TextField 和一个 Text 小部件,它们应该实时显示在 TextField 中编写的文本。 这是代码: late final TextEditingController _imp
我有 2 个自动完成 UITextField这将在输入文本时触发表格 View 。其中一个我正在使用MVPlaceSearchTextField .我使用 this 自定义构建的另一个. 当我输入 t
我创建了一个函数,可以“映射”对象数组并使用该信息创建material-ui TextField 元素。当用户输入的字符超过 maxLength 时,我尝试输出错误消息。我想仅显示用户当前通过“onC
我是一名优秀的程序员,十分优秀!