【问题标题】:When UIPickerView Value changed then table row changed in ios当 UIPickerView 值更改时,表行在 ios 中更改
【发布时间】:2014-07-09 06:18:10
【问题描述】:

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

现在我想当文本字段值改变时,表格行值改变。

我使用了以下代码

    - (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 行并将该值添加到文本字段中,以便第三行数据自动显示在 tableview 中?我说的对吗?
  • darshan 对,我只想要这种方式

标签: ios uitableview uitextfield uipickerview


【解决方案1】:

使用UITextField委托方法:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:
      //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];
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-14
        • 2014-01-09
        相关资源
        最近更新 更多