2012-11-22 58 views
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視圖只有在所有的情況下?任何一個可以幫助我梳理出來

+0

爲什麼你通過NSInteger作爲發件人?它必須是按鈕本身,而不是它的標籤 –

+0

是NSLog打印正確的標籤值? –

+0

@PratyushaTerli它總是顯示0只 – Fazil

回答

1

你應該還要設置你想通過標籤訪問的UIButtons/UIViews的標籤。像secondButton.tag = 3;並且傳遞的發送者參數不是NSInteger類型的,它是UIView的,所以改變它就像這樣!這是應該解決你的問題!

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