0

单击显示子视图视图的每个按钮都包含学习和播放选项。单击时,要显示不同的视图取决于 uibutton 选择。这是我的代码。

-(IBAction)animals
{

CGPoint point = [tap locationInView:self.animalsbut];

pv = [PopoverView showPopoverAtPoint:point inView:animalsbut withContentView:alertvu    delegate:self];
pv.tag=1;

}
-(IBAction)birds
{
   CGPoint point = [tap locationInView:self.birdsbut];

pv = [PopoverView showPopoverAtPoint:point inView:birdsbut withContentView:alertvu delegate:self];
pv.tag=2;
//[self checkingme:pv.tag];
}
-(IBAction)direct
 {  
  CGPoint point = [tap locationInView:self.direcbut];
pv = [PopoverView showPopoverAtPoint:point inView:direcbut withContentView:alertvu delegate:self];
pv.tag=4;
}
-(IBAction)fruit
{

CGPoint point = [tap locationInView:self.fruitbut];
pv = [PopoverView showPopoverAtPoint:point inView:fruitbut withContentView:alertvu delegate:self];
pv.tag=3;
}

方法

-(IBAction)check:(NSInteger)sender
{
UIButton *mybutton =(UIButton*) [self.view viewWithTag:sender];

if(pv.tag==1)
{
    NSLog(@"button log%d",mybutton.tag);
if(mybutton.tag==0)
{

    animallearn *aview=[[animallearn alloc]initWithNibName:@"animallearn" bundle:nil];
    [self.navigationController pushViewController:aview animated:YES];
    [pv performSelector:@selector(dismiss) withObject:nil afterDelay:0.1f];
}
else //(mybutton.tag==1)
{
    playview *pview=[[playview alloc]initWithNibName:@"playview" bundle:nil];
    [self.navigationController pushViewController:pview animated:YES];
   [pv performSelector:@selector(dismiss) withObject:nil afterDelay:0.1f];
}

}
else if(pv.tag==2)
{
    if(mybutton.tag==0)
    {
        birdview *aview=[[birdview alloc]initWithNibName:@"birdview" bundle:nil];
        [self.navigationController pushViewController:aview animated:YES];
        [pv performSelector:@selector(dismiss) withObject:nil afterDelay:0.1f];

    }
   else if(mybutton.tag==1)
   {
       playview *pview=[[playview alloc]initWithNibName:@"playview" bundle:nil];
       [self.navigationController pushViewController:pview animated:YES];
       [pv performSelector:@selector(dismiss) withObject:nil afterDelay:0.1f];
   }
}
else if(pv.tag==3)
{
    if(mybutton.tag==0)
    {
        fruitview *aview=[[fruitview alloc]initWithNibName:@"fruitview" bundle:nil];
        [self.navigationController pushViewController:aview animated:YES];
        [pv performSelector:@selector(dismiss) withObject:nil afterDelay:0.1f];           
    }
    else if(mybutton.tag==1)
    {
        playview *pview=[[playview alloc]initWithNibName:@"playview" bundle:nil];
        [self.navigationController pushViewController:pview animated:YES];
        [pv performSelector:@selector(dismiss) withObject:nil afterDelay:0.1f];
    }
}
else if(pv.tag==4)
{
    if(mybutton.tag==0)
    {
        directview *aview=[[directview alloc]initWithNibName:@"directview" bundle:nil];
        [self.navigationController pushViewController:aview animated:YES];
         [pv performSelector:@selector(dismiss) withObject:nil afterDelay:0.1f];
    }
    else if(mybutton.tag==1)
    {
        playview *pview=[[playview alloc]initWithNibName:@"playview" bundle:nil];
        [self.navigationController pushViewController:pview animated:YES];
        [pv performSelector:@selector(dismiss) withObject:nil afterDelay:0.1f];
    }
}
else
{

    return ;
 }
 }

这里的问题是,每当我按下第二个按钮时,它只在所有情况下显示按钮标签 0 视图?谁能帮我整理一下

4

1 回答 1

1

您还应该设置要通过标签访问的 UIButtons/UIViews 的标签。像 secondButton.tag = 3; 并且传递的 sender 参数不是 NSInteger 类型,而是 UIView,所以像这样更改它!这应该可以解决您的问题!

-(IBAction)check:(id)sender 
{
    UIButton *mybutton =(UIButton*) sender;
    // continue whatever you were doing earlier!
}
于 2012-11-22T08:06:55.770 回答