UIPickerView 不工作
UIPickerView is not working
我有一个关于如何使用 UIPickerView 的问题。我有 2 个 VC 与 Push segue 相连,其中一个我放了一个带有 5 个颜色名称的 UIPickerView,另一个我有一个 tableView,我的问题是,我想更改单元格背景的颜色我 select 它来自 PickerView,在这里我有我尝试做的代码。如果有人知道如何执行此操作,我将非常高兴。提前致谢!!!
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (row) {
case 0:
self.color.text = @"Blue #0000FF";
self.table.vi.backgroundColor= [UIColor colorWithRed:0.0f/255.0f green: 0.0f/255.0f blue:255.0f/255.0f alpha:255.0f/255.0f];
break;
case 1:
self.color.text = @"Green #00FF00";
self.view.backgroundColor = [UIColor colorWithRed:0.0f/255.0f green: 255.0f/255.0f blue:0.0f/255.0f alpha:255.0f/255.0f];
break;
case 2:
self.color.text = @"Orange #FF681F";
self.view.backgroundColor = [UIColor colorWithRed:205.0f/255.0f green: 140.0f/255.0f blue:31.0f/255.0f alpha:255.0f/255.0f];
break;
case 3:
self.color.text = @"Purple #FF00FF";
self.view.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green: 0.0f/255.0f blue:255.0f/255.0f alpha:255.0f/255.0f];
break;
case 4:
self.color.text = @"Red #FF0000";
self.view.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green: 0.0f/255.0f blue:0.0f/255.0f alpha:255.0f/255.0f];
break;
case 5:
self.color.text = @"Yellow #FFFF00";
self.view.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green: 255.0f/255.0f blue:0.0f/255.0f alpha:255.0f/255.0f];
break;
}
以及我尝试更改背景颜色的 tableView 中的代码:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
self.vi = [[UIView alloc] init];
[cell setBackgroundView:self.vi];
}
问题是当我尝试在 pickerView 所在的同一 VC 上更改背景颜色时,一切正常,但是当我尝试将其传递给另一个 class 时,它不起作用。
请帮忙!!!
几天后我解决了这个问题。在 2 类 之间发送值的最佳方式是通过 NSUserDefaults。
我有一个关于如何使用 UIPickerView 的问题。我有 2 个 VC 与 Push segue 相连,其中一个我放了一个带有 5 个颜色名称的 UIPickerView,另一个我有一个 tableView,我的问题是,我想更改单元格背景的颜色我 select 它来自 PickerView,在这里我有我尝试做的代码。如果有人知道如何执行此操作,我将非常高兴。提前致谢!!!
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (row) {
case 0:
self.color.text = @"Blue #0000FF";
self.table.vi.backgroundColor= [UIColor colorWithRed:0.0f/255.0f green: 0.0f/255.0f blue:255.0f/255.0f alpha:255.0f/255.0f];
break;
case 1:
self.color.text = @"Green #00FF00";
self.view.backgroundColor = [UIColor colorWithRed:0.0f/255.0f green: 255.0f/255.0f blue:0.0f/255.0f alpha:255.0f/255.0f];
break;
case 2:
self.color.text = @"Orange #FF681F";
self.view.backgroundColor = [UIColor colorWithRed:205.0f/255.0f green: 140.0f/255.0f blue:31.0f/255.0f alpha:255.0f/255.0f];
break;
case 3:
self.color.text = @"Purple #FF00FF";
self.view.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green: 0.0f/255.0f blue:255.0f/255.0f alpha:255.0f/255.0f];
break;
case 4:
self.color.text = @"Red #FF0000";
self.view.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green: 0.0f/255.0f blue:0.0f/255.0f alpha:255.0f/255.0f];
break;
case 5:
self.color.text = @"Yellow #FFFF00";
self.view.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green: 255.0f/255.0f blue:0.0f/255.0f alpha:255.0f/255.0f];
break;
}
以及我尝试更改背景颜色的 tableView 中的代码:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
self.vi = [[UIView alloc] init];
[cell setBackgroundView:self.vi];
}
问题是当我尝试在 pickerView 所在的同一 VC 上更改背景颜色时,一切正常,但是当我尝试将其传递给另一个 class 时,它不起作用。 请帮忙!!!
几天后我解决了这个问题。在 2 类 之间发送值的最佳方式是通过 NSUserDefaults。