点击每个按钮显示子视图视图包含学习和播放选项。点击时,想要显示不同视图取决于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视图在所有情况下?任何人都可以帮我解决它
答案 0 :(得分:1)
您还应该设置要通过标签访问的UIButtons / UIViews的标签。像secondButton.tag = 3;并且传递的sender参数不是NSInteger的类型,它是UIView,所以改变它就像这样!这应该可以解决你的问题!
-(IBAction)check:(id)sender
{
UIButton *mybutton =(UIButton*) sender;
// continue whatever you were doing earlier!
}