是否有任何理由将 UIPicker 添加到视图可能会以某种方式剥夺以编程方式创建的按钮的功能?我最初实例化了一个 UIButton 以将我带到不同的视图,一切都很好。然后我继续在同一个视图中添加了一个 UIPicker,目的是选择几个关键字段,然后可以将这些字段传递到 UIButton 导致的视图。不幸的是,我似乎在添加选择器的过程中以某种方式破坏了我的按钮。
这是按钮的实例化:
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];
我希望这些代码段足以让有人指出我误入歧途的地方,因为我现在很迷茫。