开发者

How fixed tag value for text field of custom cell in table view?

开发者 https://www.devze.com 2023-04-07 22:59 出处:网络
I am implementing a ta开发者_如何学运维b;e in which i have created a custom cell for cell of tableview. On custom cell i am displaying two text field , one button and one image view. Now i want implem

I am implementing a ta开发者_如何学运维b;e in which i have created a custom cell for cell of tableview. On custom cell i am displaying two text field , one button and one image view. Now i want implement an event on text field. That is when i click on text field then appear picker view. With the help of picker view we can change text of text field. I have applied event like as when we click on text filed then appear a picker view. But when i scroll picker view then text field value not changing. so what i will do so that it happens? In table view i have 10 rows and i want to insert value from single picker view. I have also set tag on text field of custom cell by using this code.

cell_object.txt_time.tag=[indexpath.row];

for selection value from picker view i use this code...

 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
    if (pickerView == myPicker)
    {
         if(cell_object.txt_time.tag==0)
           {
        [cell_object.txt_time setText:[NSString stringWithFormat:@"%@",[array_time objectAtIndex: [pickerView selectedRowInComponent:0]]]];
       }
      else if(cell_object.txt_time.tag==1)
           {
        [cell_object.txt_time setText:[NSString stringWithFormat:@"%@",[array_time objectAtIndex: [pickerView selectedRowInComponent:0]]]];
       }
    }
} 

I have do for 10 rows text.tag. But it is not working.

What i do ?

Thanks in advance...


A simple implementation would be:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent(NSInteger)component{
    NSString *string = [[NSString alloc] initWithFormat:@"%@",[myArray objectAtIndex:row]];
    textfield.text = string;
}

myArray is the datasource for your UIPickerView. With the above code you will be able to tweak it to what you needed to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号