2010-06-24 3 views
1

뷰에 UIPicker를 추가하면 프로그래밍 방식으로 생성 된 버튼의 기능을 손상시킬 수 있습니까? 처음에는 UIButton을 인스턴스화하여 나를 다른 견해로 데려갔습니다. 모든 것이 잘되고 잘되었습니다. 그런 다음 UIBick이 이끌어내는보기로 넘어갈 수있는 몇 가지 주요 필드를 선택하는 목적으로 동일한보기에 UIPicker를 추가했습니다. 불행히도 나는 피커를 추가하는 과정에서 어떻게 든 제 버튼을 부러 뜨린 것 같습니다. 공유 단일 개체로 전송 한 다음과 같은 게임 뷰로드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]; 

여기

버튼의 인스턴스의 나는이 순간 코드가 누군가가 길을 잃은 곳을 지적하기에 충분하다고 생각합니다. 무슨 호기심에서

+1

당신이 UIPicker 초기화 코드를 추가 할 수 있습니다 또한 insertSubview 대 addSubview에 큰 보려면 여기를 봐? 또한 도청 될 때 버튼이 시각적으로 반응합니까? – Endemic

+0

버튼 부분은 어떤 ViewController입니까? 원래 View의 인덱스 1 위에 새 ViewController를 삽입합니다. 전체 화면을 차지합니까 (버튼이있는 위치와 같이 부분이 투명해도 마찬가지입니다). ViewController 바로 아래에 버튼이 무효화되는 버튼 위에 ViewController를 올릴 수있는 것처럼 보입니다. – trumpetlicks

답변

0

당신은 대체 할 경우 :

[self.view insertSubview:switchToGame atIndex:0]; 

[self.view insertSubview:theViewController.view atIndex:0]; 

[self.view insertSubview:switchToGame atIndex:1]; 

[self.view insertSubview:theViewController.view atIndex:1]; 

버튼이 맨 위에 오도록 뷰가 올바르게 정렬되기를 바랍니다.

Difference between addSubview and insertSubview in UIView class