0

カスタムセルを追加しているテーブルビューがあります。カスタムセルにはテキストフィールドがあります。そのテキストフィールドに、ピッカービューから値を挿入します。ユーザーがテキストフィールドをクリックすると、ピッカービューが開きます。その目的のために次のコードがありますが、テキストフィールドに値がありません。コード..

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath 
    {    
        NSString *identifier = [NSString stringWithFormat:@"%d-%d",indexPath.section,indexPath.row];
        cell_object = (Custom_cell2 *)[tableView dequeueReusableCellWithIdentifier:identifier]; 
        if(cell_object == nil) 
        {
            [[NSBundle mainBundle] loadNibNamed:@"Custom_cell2" owner:self options:nil];
        }

        // Configure the cell...
        cell_object.selectionStyle=UITableViewCellSelectionStyleNone;
        cell_object.txt_name.backgroundColor=[UIColor clearColor];
        cell_object.txt_name.userInteractionEnabled=NO;
        NSArray *array = [array_from objectAtIndex:indexPath.section];
        NSString *cellValue = [array objectAtIndex:indexPath.row];  
        cell_object.txt_name.text = [NSString stringWithFormat:@"%@",cellValue];
        cell_object.txt_time.backgroundColor=[UIColor whiteColor];
        cell_object.txt_time.textColor=[UIColor blackColor];
        //cell_object.txt_time.userInteractionEnabled=NO;
        //cell_object.txt_time.text =@"";
        return cell_object;
    }

カスタムセルの上記のコード。

    -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    {
        myPicker.hidden=FALSE;
        UIToolbar *tool = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, 320, 44)]; //better code with variables to support view rotation
        tool.tintColor=[UIColor blackColor];
        UIBarButtonItem *space=[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];
        UIBarButtonItem *doneButton =[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)] autorelease];
        //using default text field delegate method here, here you could call
        //myTextField.resignFirstResponder to dismiss the views
        [tool setItems:[NSArray arrayWithObjects: space,doneButton,nil] animated:NO];
        cell_object.txt_time.inputAccessoryView = tool;
        [myPicker addSubview:tool];
        //you can -release your doneButton and myToolbar if you like
        [[[UIApplication sharedApplication] keyWindow] addSubview:myPicker];        
        return NO;
    }

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

cell_object.txt_timeをクリックすると、ピッカービューが表示されますが、テキストファイルにピッカーからの値が挿入されていません。

このコードの間違いは何ですか?

前もって感謝します...

4

3 に答える 3

0

[pickerView selectRow:1 inComponent:0 アニメーション:NO]; textField.text= [array_name objectAtIndex:[pickerView selectedRowInComponent:0]];

ピッカービューの選択からテキストを追加するためにこのコードを試すことができます...

于 2011-09-26T13:02:18.100 に答える
0

myPicker を subView として追加するときに、次の行を設定したことを確認し、コードに追加します。

    myPicker.delegate = self;
于 2011-09-26T13:04:25.667 に答える
0

実際には、このような値を設定することはできませんUITableViewCell textlLabel。tableView の変更については、それをリロードするか、セルを個別にリロードする必要があります。

解決策は、配列を作成し、pickerViewその配列に値を格納することです。

次にcellForRowAtIndexPath

cell_object.txt_time setText: [array objectAtIndex: indexPath];

これを試して..

于 2013-07-26T12:26:44.950 に答える