English 中文(简体)
如何以纽芬兰语点击来抹去主谈
原标题:How to disappear uiview by a button click

I have created a unbutton programatically and made an action

{
UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton1.frame = CGRectMake(20, 20, 80, 44); 
    [myButton1 setTitle:@"Click Me!" forState:UIControlStateNormal];
    [myButton1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:myButton1];
}

和在《国际反种族歧视公约》中,我有《国际反种族歧视公约》的一般性意见。

- (IBAction)buttonClicked:(id)sender 
{
    CGRect myFrame = CGRectMake(0, 300, 100, 50);
    UIView *myView = [[UIView alloc] initWithFrame:myFrame];
    myView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:myView];
    [myView release];
}

现在想要的是,当用户第二次报道我的Button1时,必须消失。 如何做到这一点?

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 对我们的法典作一些修改——。

**Action like this -** 

- (IBAction)buttonClicked:(id)sender 
 {
   UIView *myView;
   if([self.view viewWithTag:56])
   {
    [[self.view viewWithTag:56] removeFromSuperview];
  }
  else
  {
   CGRect myFrame = CGRectMake(0, 300, 100, 50);
   myView = [[UIView alloc] initWithFrame:myFrame];
   myView.backgroundColor = [UIColor lightGrayColor];
  [myView setTag:56];
  [self.view addSubview:myView];
  [myView release];
   }
}
问题回答

you can use [view removeFromSuperView] method to remove a view.

更改<代码>buttonClicked:方法。

- (void)buttonClicked:(id)sender 
{
UIView *myView;
if(myView=[self.view viewWithTag:1234])
{
    [myView removeFromSuperview];
}
else {
    CGRect myFrame = CGRectMake(0, 300, 100, 50);
    myView= [[UIView alloc] initWithFrame:myFrame];
    [myView setTag:1234];
    myView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:myView];
    [myView release];
}
[self.view setNeedsDisplay];
}

EDIT: It doesn t read well if you use IBAction and not use the Interface Builder.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签