我在objective-c上很新,我正在尝试使用for循环设置0.0 Alpha处的标签数组。有人能给我一个帮助吗?
NSArray *fadeLabels = @[@"_lonLabel", @"_firstLat",@"_firstLon",@"_firstReal",@"_firstMagnetic",@"_firstSpeed",@"_speedLabel",@"_realNorthLabel",@"_magneticNorthLabel"];
for (int i=0; i<[fadeLabels count]; i++) {
[fadeLabels objectAtIndex:i];
//setAlpha:0.0f?
}
答案 0 :(得分:2)
使用视图数组而不是字符串数组。在数组中插入视图。
NSArray *fadeLabels = @[ _lonLabel, _firstLat, _firstLon, _firstReal, _firstMagnetic, _firstSpeed, _speedLabel, _realNorthLabel, _magneticNorthLabel];
for (int i=0; i<[fadeLabels count]; i++) {
UIView *view = (UIView *)[fadeLabels objectAtIndex:i];
[view setAlpha:0.0f];
}
答案 1 :(得分:1)
您正在使用String
分配数组,其名称为equalTo
您的UILabel
对象,因此您需要
替换像这样的数组元素
@"_lonLabel"
至_lonLabel
NSArray *fadeLabels = @[ _lonLabel, _firstLat, _firstLon, _firstReal, _firstMagnetic, _firstSpeed, _speedLabel, _realNorthLabel, _magneticNorthLabel];
for (int i=0; i<[fadeLabels count]; i++) {
UILabel *label = (UILabel *)fadeLabels[i];
label.alpha = 0.0;
}
答案 2 :(得分:1)
您还应该更好地使用KEYS [0-9]*
代替&#34; old&#34; for...in
。
for