2011-08-11 26 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获取的条件。所以当我点击右边的按钮时,应该打开一个新的视图,它应该获取forecat条件标签fron xml并显示在它上面,当我点击右边的按钮时它应该再次显示当前的条件。即它应该在循环中。如果我点击左边的按钮,则应显示预测条件。这怎么可能?

+0

您是否实施了播放和播放操作?对于每个视图也有更好的控制器。 –

+0

@praveen不,我没有实施游戏动作 – Rani

+0

视图控制器会工作得更好,并且更容易实现。试试吧...... –

回答

1

您只需用另一个视图替换newView即可。要做到这一点,你应该首先设置newView的tag

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

playAction,得到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,因为你告诉按钮点击视图类被调用,但我有一个概率。我正在获取tableview的行值并在uiview中显示,但为了显示目的,tableview保持隐藏.so当我在switch case中调用indexpath.row时,我的断点没有进入它。 – Rani

+0

对不起,我不明白桌子从哪里进来?我以为你想在按下几个按钮时改变视图。 – Akshay

相关问题