ios - 更改 UISegmentedControl 文本

标签 ios xcode

我正在尝试更改我在 IB 中制作的 UISegmentedControl 的文本。这是代码

[changeButton removeAllSegments];
[changeButton insertSegmentWithTitle:NSLocalizedString(@"Traffic",@"traffic string")  atIndex:0 animated:YES];
[changeButton insertSegmentWithTitle:NSLocalizedString(@"Satellite",@"satellite string")  atIndex:1 animated:YES];

但什么也没发生:我总是看到 IB 为我放置的默认标签(“第一”和“第二”)。 当然,我将 IBOUtlet 放在我的 .h 中:

 __weak IBOutlet UISegmentedControl *changeButton;

我错过了什么?一般来说,当我在IB中创建控件时,为了以编程方式访问它,将IBOutlet放入.h中是正确的方法吗?

最佳答案

__weak

哦等等...如果它很弱,它会在作用域结束时被释放并为空(当创建它的方法返回时)。省略 __weak 应该没问题。

关于ios - 更改 UISegmentedControl 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13561891/

相关文章:

ios - 如何居中 KC FloatingActionButton

ios - Swift 4.0 中的空闭包

Xcode:找不到控件的 rgb 颜色选择器

ios - 让警告在嵌套的CloudKit查询中使var永不更改

iphone - CGContext 和视网膜显示

ios - 在多线程 Swift 中处理来自 AVFoundation 的视频帧

ios - 如何删除 CarPlay ListView 中的云图标?

php - 运行 IOS 应用程序需要什么类型的编程

ios - 在设备上记录数据并检索日志

ios - 删除插入分组 UITableView 上方的空间