ビューにUIPickerを追加すると、プログラムで作成されたボタンの機能が失われる可能性がある理由はありますか?最初にUIButtonをインスタンス化して別のビューに移動しましたが、すべて問題ありませんでした。次に、UIButtonが移動したビューに渡すことができるいくつかのキーフィールドを選択する目的で、同じビューにUIPickerを追加しました。残念ながら、ピッカーを追加する過程でボタンが壊れたようです。
ボタンのインスタンス化は次のとおりです。
switchToGame = [UIButton buttonWithType:UIButtonTypeRoundedRect];
switchToGame.frame = CGRectMake(140,250,100,100);
[switchToGame setTitle:@"Play God" forState:UIControlStateNormal];
[switchToGame setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[switchToGame addTarget:self action:@selector(playGame) forControlEvents:UIControlEventTouchUpInside];
[self.view insertSubview:switchToGame atIndex:0];
メソッドplayGameは、ピッカーのフィールドをチェックし、それらを共有シングルトンオブジェクトに送信してから、ゲームビューを次のようにロードします。
Singleton *mySingleton = [Singleton sharedSingleton];
NSInteger numCellsRow = [theDataPicker selectedRowInComponent:0];
NSInteger aliveColorRow = [theDataPicker selectedRowInComponent:1];
NSInteger deadColorRow = [theDataPicker selectedRowInComponent:2];
UIColor * theAliveColor = [aliveColors objectAtIndex:aliveColorRow];
UIColor * theDeadColor = [deadColors objectAtIndex:deadColorRow];
NSInteger numCellsPerRow = [[cellRowOptions objectAtIndex:numCellsRow] intValue];
mySingleton.cellsPerRow = numCellsPerRow;
mySingleton.aliveColor = theAliveColor;
mySingleton.deadColor = theDeadColor;
[theAliveColor release];
[theDeadColor release];
GameController * viewController = [GameController alloc];
self.theViewController = viewController;
[self.view insertSubview:theViewController.view atIndex:1];
[viewController release];
私は今のところかなり迷っているので、これらのコードの範囲が、私がどこを迷ったのかを誰かが指摘するのに十分であることを願っています。