【发布时间】:2011-02-06 11:36:58
【问题描述】:
出于美学原因,我在分段控件上显示货币符号,但我想以 3 个字母返回货币代码。看看我是怎么做到的:
NSArray *itemArray = [NSArray arrayWithObjects: @"EUR", @"USD", @"GBP", nil];
self.writePriceCurrency = [[UISegmentedControl alloc] initWithItems:itemArray];
[self.writePriceCurrency setTitle:@"€" forSegmentAtIndex:0];
[self.writePriceCurrency setTitle:@"$" forSegmentAtIndex:1];
[self.writePriceCurrency setTitle:@"£" forSegmentAtIndex:2];
我知道我可以在函数中使用switch() {} 来捕获值的变化并根据索引返回正确的代码,但这将是硬编码的。我宁愿直接这样做,以便将来可以动态更改分段控件。
您能帮我理解我们如何获取与所选片段对应的项目吗?
【问题讨论】:
标签: iphone objective-c xcode uisegmentedcontrol