如何解决选择一个选择器会导致UIbutton图像更改
| 我一直在寻找一种构建UIpicker的方法,选择该行将导致UIbutton图像的更改。通常的if,else方法更改按钮似乎在这里不起作用。有谁知道该怎么做? 这是我找到并正在使用的模型代码。我该如何修改? 非常感谢。@synthesize button;
// Implement viewDidLoad to do additional setup after loading the view,typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
arrayColors = [[NSMutableArray alloc] init];
[arrayColors addObject:@\"Orange\"];
[arrayColors addObject:@\"Yellow\"];
[arrayColors addObject:@\"Green\"];
[arrayColors addObject:@\"Blue\"];
[arrayColors addObject:@\"Indigo\"];
[arrayColors addObject:@\"Violet\"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn\'t have a superview
// Release anything that\'s not essential,such as cached data
}
- (void)dealloc {
[arrayColors release];
[super dealloc];
}
#pragma mark -
#pragma mark Picker View Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
return [arrayColors count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [arrayColors objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@\"Selected Color: %@. Index of selected color: %i\",[arrayColors objectAtIndex:row],row);
}
@end
解决方法
在didSelectRow方法中,您可以检查以查看选择了哪个索引。然后从那里创建if语句。如果由于某种原因不能正常工作,那么我将创建一个NSTimer来每1秒检查一次值。如果选择器的值更改,那么更改图像按钮吗?多数民众赞成在第一件事突然出现在我的脑海。
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger )component {
//component is the entire colomn on a picker \"all of your colors\"
if (component == 0) {
//row is the selected item in the colomn \"orange\"
if (row == 0) {
//color was selected
//change image here
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。