当UIPickerView Value更改时,表行在ios中更改

时间:2014-07-09 06:18:10

标签: ios uitableview uitextfield uipickerview

在我的UIview中,单击文本字段后我UITextField,然后使用UIPickerView。然后我选择值,这个值在textField中。

现在我希望当textfield值改变然后表行值改变。

我使用了以下代码

    - (void)viewDidLoad:
    {
        [super viewDidLoad];

        [self loadCriteria];
        UILabel * projectDetailLable = [[UILabel alloc] initWithFrame:CGRectMake(0,[topBar bottom],320, 30)];
        projectDetailLable.textColor = [UIColor whiteColor];
        projectDetailLable.backgroundColor = UIColorFromRGB(0x28a0d8);
        projectDetailLable.font = [UIFont boldSystemFontOfSize:16];
        projectDetailLable.text = @"Choose Criteria Category:";
        projectDetailLable.textAlignment = NSTextAlignmentLeft;
        [self.view addSubview:projectDetailLable];


        criteriaTextField = [[UITextField alloc] initWithFrame:CGRectMake(2, [projectDetailLable bottom]+2, 316, 30)];
        criteriaTextField.borderStyle = UITextBorderStyleLine;
        // criteriaTextField.text = @"Health & Well being";


        criteriaTextField.font = [UIFont systemFontOfSize:13];
        [self.view addSubview:criteriaTextField];

        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = criteriaTextField.frame;
        [button addTarget:self action:@selector(launchCriteriaPicker) forControlEvents:UIControlEventTouchUpInside];


        [self.view addSubview:button];


        caseStudyTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, [criteriaTextField bottom]+5, 320, self.view.frame.size.height )];
        if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){
            [caseStudyTableView setSeparatorInset:UIEdgeInsetsZero];
        }
        caseStudyTableView.delegate = self;
        caseStudyTableView.dataSource = self;
        caseStudyTableView.rowHeight = 40;
        caseStudyHeaderView.backgroundColor = [UIColor clearColor];
        [self.view addSubview:caseStudyTableView];
    }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    [ cell.textLabel setFont:[UIFont boldSystemFontOfSize:13]];
    [ cell.textLabel setTextAlignment:NSTextAlignmentLeft];
    cell.textLabel.numberOfLines=0;
    [ cell.textLabel setTextColor:[UIColor blackColor]];
    cell.textLabel.backgroundColor = UIColorFromRGB(0xc8f898);
    cell.contentView.backgroundColor = UIColorFromRGB(0xc8f898);

    NSLog(@"%@",criteriaNameArray);
    cell.textLabel.text = [criteriaNameArray objectAtIndex:indexPath.row];
    return cell;
}

如何更改IOS中的表值。

3 个答案:

答案 0 :(得分:0)

使用UITextField委托方法:

- (void)textFieldDidEndEditing:(UITextField *)textField{

   // [criteriaNameArray replaceObjectAtIndex:atIndexToReplace withObject:textField.text];
   [self.tableView reloadData]; // Handle the DataSource accordingly in the cellForRowAtIndexPath
}

答案 1 :(得分:0)

在pickerview didselect方法中尝试[tableView reloadData];

答案 2 :(得分:0)

//in view did load listen for text changed notification
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(textFieldChanged:)
                                             name:UITextFieldTextDidChangeNotification
                                           object:yourTextField]

//Reload the table view Whenever the text field changes the text
-(void)textFieldChanged:(id)sender{


    [yourTableView reloadData];

}