2011-08-11 4 views
0

나는 두 개의 버튼이있는 uiview를 가지고있는 응용 프로그램을 가지고 있습니다. 나는 이런 식으로 내 uiview의 프레임을 설정했습니다.uiview를 iPhone에서 버튼 클릭으로 표시하는 방법

newview = [[UIView alloc]initWithFrame:CGRectMake(0,350,320,70)]; 

나는 두 개의 버튼을 추가 한 새로운보기로

[self.view addSubview:newview]; 

다음 내 기본보기로 설정합니다. 새보기의 오른쪽에있는 새 단추 및 다른 단추의 왼쪽에있는 하나의 단추.

이 내가이 버튼을 클릭하면 이제 내가 원하는

leftnavbutton= [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 
      leftnavbutton.backgroundColor = [UIColor clearColor]; 
      [leftnavbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ]; 

UIImage *buttonImageleft = [UIImage imageNamed:@"previous_large.png"]; 
      //UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 

[leftnavbutton setBackgroundImage:buttonImageleft forState:UIControlStateNormal]; 
      [leftnavbutton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside]; 
[leftnavbutton setFrame:CGRectMake(23, 28, 8, 44)]; 
      [newview addSubview:leftnavbutton]; 



rightnavbutton= [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 
      rightnavbutton.backgroundColor = [UIColor clearColor]; 
      [rightnavbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ]; 

UIImage *buttonImageright = [UIImage imageNamed:@"next_large.png"]; 
      //UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];    

[rightnavbutton setBackgroundImage:buttonImageright forState:UIControlStateNormal];   

[rightnavbutton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];   

[rightnavbutton setFrame:CGRectMake(275, 28, 8, 44)]; 
[newview addSubview:rightnavbutton]; 

버튼

내 코드입니다. 새로운 관점이 새로운 관점으로 바뀌어야합니다. 예를 들어, xml에서 가져온 새로운 뷰가 현재 표시되어있는 새 뷰에서 응용 프로그램을 실행할 때. 그래서 오른쪽 버튼을 클릭하면 forecsat 조건 태그 fron xml을 가져 와서 표시해야하는 새보기가 열리 며 오른쪽 버튼을 클릭하면 다시 현재 조건이 표시됩니다. 즉 루프에 있어야합니다. 왼쪽 버튼을 클릭하면 againg 예측 조건이 표시됩니다. 이것이 어떻게 가능한지?

+0

게임을 실행하고 실행 했습니까? 또한 각보기에 대해 제어기를 갖는 것이 더 좋습니다. –

+0

@praveen no 플레이 액션을 구현하지 않았습니다. – Rani

+0

View 컨트롤러가 훨씬 잘 작동하고 구현하기가 더 쉬울 것입니다. 그것을 밖으로 시도해보십시오 ... –

답변

1

newView을 다른보기로 바꾸면됩니다. 그렇게하려면 먼저 newView의 tag을 설정해야합니다. playAction에서

newview = [[UIView alloc]initWithFrame:CGRectMake(0,350,320,70)]; 
newView.tag = 7; // set whatever number you want 
[self.view addSubview:newview]; 

newView 잡아와 superView에서 제거합니다. 그런 다음 다른 위치에보기를 추가하십시오.

-(void)playAction:(id)sender 
{ 
    UIView* newView = [self.view viewWithTag:7]; 
    [newView removeFromSuperView]; 

    //create and add the new new view that should replace new view. Use the same frame. 
    UIView* newnewview = [[UIView alloc]initWithFrame:CGRectMake(0,350,320,70)]; 
    newnewView.tag = 7; // set whatever number you want 
    [self.view addSubview:newnewview]; 

     //Add the left & right buttons again, as they were removed when newView was removed 
     ... code to add buttons... 
} 

마찬가지로, play: 방법이 구현 될 수있다.

+0

안녕하세요 akshay로 u는 버튼 클릭 클래스보기라고하지만 나는 prob있다. 나는 tableview의 행 값을 가져 와서 uiview에 표시하지만 표시 목적으로 tableview는 숨겨져 있습니다 .so는 스위치 케이스에서 indexpath.row를 호출 할 때 내 브레이크 포인트가 입력되지 않습니다. – Rani

+0

테이블이 어디서 왔는지 이해할 수 없다니 유감입니다. 몇 개의 버튼을 눌렀을 때보기를 바꾸고 싶다고 생각했습니다. – Akshay

관련 문제