Fazil
Fazil

Reputation: 1390

multi button tag multi ple view

On click each button showing subview view contains learn and play option.While clicking , want to show the different view depends on the uibutton selection.Here my code .

-(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;
}

method

-(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 ;
 }
 }

Here problem is whenever i second button it showing the button tag 0 view only in all the cases?Can any one help me to sort it out

Upvotes: 0

Views: 102

Answers (1)

Asif Mujteba
Asif Mujteba

Reputation: 4656

You should also set the tags of UIButtons/UIViews you want to access via tag. like secondButton.tag = 3; and the sender argument passed is not of type NSInteger it is of UIView, so change it like this! This is should solve your problem!

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

Upvotes: 1

Related Questions