试图将ILColorPicker移植到iPad应用程序

时间:2012-04-11 14:34:16

标签: objective-c xcode4

我正在尝试将ILColorPicker移植到使用Storyboard的iPad应用程序。

我在UIViewController中放了一个UIView;在UIView我还有其他3个UIViews(灰色下面,包含UIView的黑色背景,给它边框)。 enter image description here

3个视图中的每个视图都具有与样本匹配的连接。

此连接图片适用于顶级UIView。 enter image description here

这是中间UIView的连接图像 enter image description here

这是底部UIVIew的连接图像 enter image description here

当我在模拟器中运行应用程序,然后单击此控制器的菜单选项卡按钮时,除了黑屏外什么都没有。另外,我把NSLog放在“viewDidLoad”中,它经历了六(6)次!

我已经为此工作了一个多星期了,并且已经达到了我的经验和知识可以帮助我的结束。有人可以帮我弄清楚这里有什么问题吗?我真的非常感激。 (如果需要,将提供代码;只是不想在这里写一本书!):D

更新:“viewDidLoad”的代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"viewDidLoad");
    //  Build a random color to show off setting he color on the iPad
    UIColor *c = [UIColor colorWithRed:(arc4random()%100)/100.0f
                                 green:(arc4random()%100)/100.0f
                                 blue:(arc4random()%100)/100.0f
                                 alpha:1.0];

    colorChip.backgroundColor = c;
    colorPicker.color = c;
    huePicker.color = c;
}

更新2:“didFinishLaunchingWithOptions

的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

1 个答案:

答案 0 :(得分:1)

我不确定你的代表是什么设置的,但是你应该将它们连接到控制器而不是视图。如果说你确定你的IBOutlets是连接的,我使用断言进行检查。

从一个带有单一视图+视图控制器的空白故事板项目中,我看到了类似于你所拥有的东西,这就是我所得到的:

  // ViewController.h
  @protocol MyPickerDelegate <NSObject>
  - (void)myPickerDidPick:(id)sender;
  - (void)myPickerPickColor:(id)sender color:(UIColor*)color;
  @end

  @interface ViewController : UIViewController<MyPickerDelegate>
  @property (weak) IBOutlet __weak UIView *colorBar;
  @property (weak) IBOutlet __weak UIView *saturationBrightnessPicker;
  @property (weak) IBOutlet __weak UIView *huePicker;
  @end

  // ViewController.m
  @interface ViewController () {
    __weak UIView *colorBar_;
    __weak UIView *saturationBrightnessPicker_;
    __weak UIView *huePicker_;
  }
  @end

  @implementation ViewController

  @synthesize colorBar = colorBar_;
  @synthesize saturationBrightnessPicker = saturationBrightnessPicker_;
  @synthesize huePicker = huePicker_;

  - (void)viewDidLoad {
    [super viewDidLoad];

    NSAssert(colorBar_, @"colorBar not connected");
    NSAssert(saturationBrightnessPicker_, @"saturationBrightnessPicker not connected");
    NSAssert(huePicker_, @"huePicker not connected");

    self.view.backgroundColor = [UIColor blackColor];  
    colorBar_.backgroundColor = [UIColor redColor];
    saturationBrightnessPicker_.backgroundColor = [UIColor greenColor];
    huePicker_.backgroundColor = [UIColor blueColor];
  }

  - (void)myPickerDidPick:(id)sender {
    NSLog(@"Did pick");
  }

  ...

  @end

希望这有帮助!