2013-05-06 212 views
0

我創建包含在父視圖的底部3個按鈕隱藏的表單,通過按下另一個按鈕,視圖變得可見,但是那些3個按鈕沒有按下。我不太知道什麼問題是。添加按鈕

我通過代碼添加一個按鈕。這是按下按鈕時調用的方法。

- (IBAction) addData:(id)sender 

{

if(attachInfo==nil){ 
     float screenHeight = self.view.frame.size.height; 
     attachInfo=[[UIView alloc] initWithFrame:CGRectMake(0, screenHeight, 320, 216)]; 



     UIButton *attachImage = [UIButton buttonWithType:UIButtonTypeCustom]; 
     //attachImage.enabled = YES; 
     [attachImage addTarget:self action:@selector(addImage:) forControlEvents:UIControlEventTouchUpInside]; 
     [attachImage setFrame:CGRectMake(20, 20, 0, 0)]; 
     [attachImage setImage:[UIImage imageNamed:@"add_photos"] forState:UIControlStateNormal]; 
     [attachImage sizeToFit]; 
     [attachInfo addSubview:attachImage]; 



     UIButton *attachDoc = [UIButton buttonWithType:UIButtonTypeCustom]; 
     //[pushButton addTarget:self action:@selector(pushViewController) forControlEvents:UIControlEventTouchUpInside]; 
     [attachDoc setFrame:CGRectMake(120, 20, 80, 80)]; 
     [attachDoc setImage:[UIImage imageNamed:@"add_docs.png"] forState:UIControlStateNormal]; 
     [attachDoc sizeToFit]; 
     [attachInfo addSubview:attachDoc]; 

     UIButton *attachPlace = [UIButton buttonWithType:UIButtonTypeCustom]; 
     //[pushButton addTarget:self action:@selector(pushViewController) forControlEvents:UIControlEventTouchUpInside]; 
     [attachPlace setFrame:CGRectMake(220, 20, 80, 80)]; 
     [attachPlace setImage:[UIImage imageNamed:@"add_place.png"] forState:UIControlStateNormal]; 
     [attachPlace sizeToFit]; 
     [attachInfo addSubview:attachPlace]; 

     //[self.view addSubview:attachInfo]; 
     [self.view addSubview:attachInfo]; 

     [UIView animateWithDuration:0.3f animations:^{ 
      CGRect frame = attachInfo.superview.frame; 
      frame.origin.y -= 216; 
      attachInfo.superview.frame=frame; 
     }]; 






    } 
    else 
    { 
     [UIView animateWithDuration:0.3f animations:^{ 
      CGRect frame = attachInfo.superview.frame; 
      frame.origin.y += 216; 
      attachInfo.superview.frame=frame; 
     }]; 
     attachInfo=nil; 
    } 



} 
+4

向我們展示一些代碼上下工夫;) – Ushan87 2013-05-06 11:05:46

+0

請發表您的用於顯示view.Whether您添加編碼或XIB這些按鈕的代碼?清楚解釋。 – NSUserDefault 2013-05-06 11:05:49

+0

郵政編碼,你試過嗎? – Rushabh 2013-05-06 11:05:49

回答

0

你需要添加按鈕的作用。

- (IBAction)first:(id)sender; 
    { 

    firstViewController * fvc=[FirstViewController alloc]init]; 

    [FirstButton setHidden:False]; 


    [self.navigationController pushViewController:fvc animated:YES]; 




    } 
    - (IBAction)Second:(id)sender; 
    { 

    SecondViewController * svc=[SecondViewController alloc]init]; 


    [SecondButton setHidden:False]; 

    [self.navigationController pushViewController:svc animated:YES]; 

    } 
    - (IBAction)Third:(id)sender; 
    { 

    ThirdViewController * tvc=[ThirdViewController alloc]init]; 

    [ThirdButton setHidden:False]; 

    [self.navigationController pushViewController:fvc animated:YES]; 

    } 
+0

按鈕是掛起的方法。 – Max 2013-05-06 11:15:36

+0

他不想解僱任何方法。他只是想啓用按鈕點擊..? – Mani 2013-05-06 11:16:51

+0

檢查您的xib您的插座和IBAction連接是否正確連接或沒有。 – Jitendra 2013-05-06 11:17:28

0

在第一個按鈕(attachImage)中,高度和寬度爲零。所以它不應該是可見的。對於其他兩個按鈕,您尚未設置目標。所以那些是不可點擊的。

爲第一個按鈕設置

[attachImage setFrame:CGRectMake(20, 20, 80, 80)]; 

和其他兩個按鈕添加

//for the second button 
[attachDoc addTarget:self action:@selector(addImage:) forControlEvents:UIControlEventTouchUpInside]; 

//for the third button 
[attachPlace addTarget:self action:@selector(addImage:) forControlEvents:UIControlEventTouchUpInside]; 
+0

這是行不通的(( – Max 2013-05-06 12:41:02

+0

你有沒有改變框的大小和這些目標添加到您的另外兩個按鈕? – Ushan87 2013-05-06 12:45:23

+0

我嘗試了所有的選項,沒有什麼工作 – Max 2013-05-06 13:02:12

0
-(void)createHiddenForm 
{ 
    hiddenView = [[UIView alloc] initWithFrame:CGRectMake(0,100,320,300)]; 
    [hidden setHidden:TRUE]; 

    [self.view addSubview:hiddenView]; 

    float posY = 50.0; 

    for (int i=0 ; i<3 ; i++) 
    { 
     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [button setFrame:CGRectMake(50,posY, 100, 50)]; 
     [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

     [hiddenView addSubview:button]; 

     posY=posY+60; 
    } 
} 

-(void)showHiddenView 
{ 
     hidden.hidden = FALSE; 
     [self.view bringSubviewToFront:hiddenView]; 
} 

-(void)buttonClicked:(id)sender 
{ 
     UIButton *senderBtn = (UIButton *)sender; 

     NSLog(@"Sender Button's tag = %@",senderBtn.tag); 
} 

希望它會幫助你。

0
float screenHeight = self.view.frame.size.height; 
attachInfo=[[UIView alloc] initWithFrame:CGRectMake(0, screenHeight, 320, 216)]; 

從以上所述,您可以在視圖邊界之外添加attachInfo Y位置。 在視圖外添加按鈕onclick將不起作用。

使其工作取代下面的線。

[UIView animateWithDuration:0.3f animations:^{ 
     CGRect frame = attachInfo.superview.frame; 
     frame.origin.y -= 216; 
     attachInfo.superview.frame=frame; 

而不是移動超視圖幀移動attachInfo框架就像這樣。

[UIView animateWithDuration:0.3f animations:^{ 
     CGRect frame = attachInfo.frame; 
     frame.origin.y -= 216; 
     attachInfo.frame=frame; 

因此,attachInfo視圖將被添加到超級視圖邊界與動畫。

+0

如何使這項工作?我創建的屏幕外的視圖,添加按鈕和scrollView,並將其與動畫塊,超級視圖一起移動,但沒有任何元素不起作用(( – Max 2013-05-10 23:21:23