iphone - 多按钮标签多 View

标签 iphone ios uibutton

单击时显示 subview View 的每个按钮都包含学习和播放选项。单击时,想要显示不同的 View 取决于 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 View ?任何人都可以帮我解决这个问题

最佳答案

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

-(IBAction)check:(id)sender 
{
    UIButton *mybutton =(UIButton*) sender;
    // continue whatever you were doing earlier!
}

关于iphone - 多按钮标签多 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13508199/

相关文章:

ios - 如何存储所有选定的按钮值并在 UILabel 上显示它们?

iphone - 在 IOS 中检测拍手

ios - 如何绕圆旋转CAShapeLayer弧?

ios - 在 UIButton 中使用 UIBarButtonItem 图标

iOS:使 UIButton 始终显示在所有 View 的前面

ios - Xcode 6.3 在打开 XIB 文件后卡住/挂起

iphone - 将 BOOL 传递给 makeObjectsPerformSelector :withObject:

ios - 更改源文档后,UIWebView 不会在我的 iOS 应用程序中刷新位于我的服务器上的 PDF 文件

iphone - Apple BLTE 传输示例应用程序的问题

ios - 遍历静态 TableView 中的所有标签