zoukankan      html  css  js  c++  java
  • iOS :UIPickerView reloadAllComponets not work

    编辑信息页面用了很多选择栏,大部分都用 UIPickerView 来实现。在切换数据显示的时候, UIPickerView 不更新数据,不得其解。Google 无解,原因在于无法描述自己的问题,想想应该还是代码哪里写错了。

    写了个测试方法,预期效果出现,于是与远方法兑换了一下,才发现问题所在:

        [self addChildViewController:self.pickerController];
        CGRect rect = CGRectOffset(self.view.bounds, 0, self.view.bounds.size.height);
        self.pickerController.view.frame = rect;
        [self.view addSubview:self.pickerController.view];
        [self.pickerController reloadData:[self.houseAttributes objectForKey:_key] selectedValue:@"高层"];
    
        [UIView animateWithDuration:0.25 animations:^{
            self.pickerController.view.frame = self.view.bounds;
        } completion:^(BOOL finished) {
        }];

    如代码所示,每次显示 UIPickerView 时,会把它 add 到主视图上,而 reloadAllComponents Not Work 的原因是因为把更换数据的方法写在了 addSubview 之前。

    #总结

    如果 UIPickerView 不存在 superView,那么调用 reloadAllComponents 会不起作用。

  • 相关阅读:
    第六章 函数与宏定义实验
    第五章 循环结构实验
    第五章 循环结构课内反思
    第四章 分支结构实验
    C程序设计实验报告
    509寝室小组
    第九章 构造数据类型实验
    第八次实验报告
    数组实验
    函数与宏定义实验
  • 原文地址:https://www.cnblogs.com/ihojin/p/ios-uipickerview-reloadallcomponents.html
Copyright © 2011-2022 走看看