-2

我正在使用下面的代码,我想将选定的颜色传递给另一个类,但它给了我以下警告并且不起作用:

从 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];
}
4

1 回答 1

1

备选方案 1:

- (void)colorPickerViewController:(NEOColorPickerBaseViewController *)controller didSelectColor:(UIColor *)color
{
 SecondClass *second = [[SecondClass alloc]init];
 second.selectColor = 控制器。选定的颜色;
 NSLog(@"选择的颜色 %@",second.selectColor);

[控制器dismissViewControllerAnimated:YES完成:无];
 }

由于 NEOColorPickerBaseViewController 是 NEOColorPickerViewController 的一个实例,这应该可以工作。

备选方案 2:

似乎您在 SecondClass 中选择的颜色是 NSString 而不是 UIColor。所以你得到了那个警告。

于 2013-10-25T15:23:19.650 回答