2013-10-25 109 views
-2

我使用下面的代碼,我想選擇的顏色傳遞給另一個類,但它給了我下面的警告並不起作用:如何從一個類傳遞的UIColor對象到另一個類

不兼容的指針類型分配給從的UIColor的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]; 
} 
+2

什麼是警告? – Peres

+0

你如何調用colorPickerViewController? –

+0

不兼容的指針類型從uicolor強分配給nsstring強 –

回答

1

Alternati ve 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:

這似乎是在二等您選擇的顏色是一個的NSString代替的UIColor。所以你得到了這個警告。

+0

是我使用nsstring而不是uicolor,但stil selectedColor不適用於UIView –

+0

如何將顏色應用於SecondClass? –

+0

second.view.backgroundColor = selectedColor ?? –

相關問題