display the key value in textfield.
this is how I am fetching data:
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if (txtviolation.editing == YES)
{
pickerV = [[UIPickerView alloc]init];
pickerV.dataSource = self;[![enter image description here][1]][1]
pickerV.delegate = self;
pickerV.showsSelectionIndicator = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(done)];
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-pickerV.frame.size.height-50, 320, 50)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
NSArray *toolbarItems = [NSArray arrayWithObjects:doneButton, nil];
[toolBar setItems:toolbarItems];
txtviolation.inputView = pickerV;
txtviolation.inputAccessoryView = toolBar;
flag=1;
}
else if (txttype.editing == YES)
{
pickerV = [[UIPickerView alloc]init];
pickerV.dataSource = self;
pickerV.delegate = self;
pickerV.showsSelectionIndicator = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(done)];
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-pickerV.frame.size.height-50, 320, 50)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
NSArray *toolbarItems = [NSArray arrayWithObjects:
doneButton, nil];
[toolBar setItems:toolbarItems];
txttype.inputView = pickerV;
txttype.inputAccessoryView = toolBar;
flag=2;
}
}
this is how display data:
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (flag==1)
{
return ViolationA.count;
}
else if (flag==2)
{
return VTypeA.count;
}
return 0;
}
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (flag==1)
{
return [NSString stringWithFormat:@"%@", [ViolationA objectAtIndex:row]];
}
else if (flag==2)
{
return [NSString stringWithFormat:@"%@", [VTypeA objectAtIndex:row]];
}
return 0;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (flag==1)
{
// [txtviolation setText:[[ViolationA objectAtIndex:row] forKeyPath:@"violation_name"]];
txtviolation.text =[NSString stringWithFormat:@"%@", [ViolationA objectAtIndex:row]];
}
else if (flag==2)
{
txttype.text = [NSString stringWithFormat:@"%@", [VTypeA objectAtIndex:row]];
}
}
I am not able to bind:
click on textfield then open the uipicker view but not display title name only display the '{' sign.
then roll it to set value of array key and value also but I am only set the value.
uitextfield setvalue:
{ "violation_name" = "Street Light"; }
and
uipickerview display:
{
{
{
then to select any value to set in text field.
uipickerview perform to select the text field not use any button