我正在使用下面的代码,我想将所选颜色传递给另一个类,但是它给了我以下警告并且不起作用:
从uicolor strong分配给nsstring的不兼容指针类型:
代码:
-(IBAction)showpickerview
{
NEOColorPickerViewController *controller = [[NEOColorPickerViewController alloc] init];
controller.delegate = self;
//controller.selectedColor = self.currentColor;
controller.title = @"Select Color";
UINavigationController* navVC = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentViewController:navVC animated:YES completion:nil];
}
- (void)colorPickerViewController:(NEOColorPickerBaseViewController *)controller didSelectColor:(UIColor *)color
{
SecondClass *second = [[SecondClass alloc]init];
second.selectColor = color;
NSLog(@"selected color %@",second.selectColor);
//UIColor *color1 = color;
//const CGFloat *components = CGColorGetComponents(color.CGColor);
//second.selectColor = [NSString stringWithFormat:@"%f,%f,%f,%f", components[0], components[1], components[2], components[3]];
//NSLog(@"selected color %@",second.selectColor);
[controller dismissViewControllerAnimated:YES completion:nil];
}
答案 0 :(得分:1)
备选方案1:
- (void)colorPickerViewController:(NEOColorPickerBaseViewController *)controller didSelectColor:(UIColor *)color { SecondClass *second = [[SecondClass alloc]init]; second.selectColor = controller. selectedColor; NSLog(@"selected color %@",second.selectColor); [controller dismissViewControllerAnimated:YES completion:nil]; }
由于NEOColorPickerBaseViewController是NEOColorPickerViewController的一个实例,因此应该可以使用。
备选方案2:
似乎您在SecondClass中选择的颜色是NSString而不是UIColor。所以你得到了警告。