ios - 如何更新 UISegmentedControl

标签 ios objective-c uitableview nsarray uisegmentedcontrol

我正在构建一个应用程序,我希望我的用户可以在其中根据一个条件(他们工作的公司)过滤一组数据(员工)。我想使用 UISegmentedControl 来做到这一点。 我还想允许我的用户随时编辑公司广告数组,当他/她这样做时,需要更新 UISegmentedControl(以便正确过滤员工),具体取决于公司中的公司数量数组。

我已经尝试了一段时间,但我不知道该怎么做。 任何帮助将不胜感激!

最佳答案

删除所有段

[self.segmentedControl removeAllSegments];

插入新的

  for (NSString *title in self.employees.reverseObjectEnumerator) { //reverse to keep the ordering
    [self.segmentedControl insertSegmentWithTitle:title atIndex:0 animated:NO];
  }

框架会自动更新,但您可能希望重新居中分段控件

  self.segmentedControl.frame = CGRectMake(floorf(self.view.frame.size.width - self.segmentedControl.frame.size.width) / 2,
                                           floorf(self.view.frame.size.height - self.segmentedControl.frame.size.height) / 2,
                                           self.segmentedControl.frame.size.width,
                                           self.segmentedControl.frame.size.height);

关于ios - 如何更新 UISegmentedControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23843002/

相关文章:

ios - 如何以编程方式填充 ScrollView 宽度

iphone - UIScrollview 滚动不流畅

iphone - UITableViewCell 附件类型在点击时选中并设置其他未选中

ios - 单行文本在 UILabel 中占用两行

ios - swift : Get tableView indextPath/textLabel from selected UIView

ios - 单个 iPhone 应用程序中可设置的最大 NSTimer 数

iphone - 如何从 TableView IOS 中删除一行

ios - 将Firebase的数据库与Swift 4语言同步

ios - 无法在可扩展表格 View 单元格中定位 UIElement(开关)

ios - 如何在 Realm Swift 中进行嵌套查询?