UIVIEW SHOW AND HIDE ON CLICK ISSUE

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
iPhone 
 1515  View(s)
Ratings:
Rate this:
Hi,

The following code which i used to show the view on click and hide when i clicks again,It works fine, But when Click again and again the view not hide any more and simply stays in the view.

- (IBAction)didTapFlag:(id)sender
{
checkBtnCondition=YES;
menuView.hidden=YES;
if([audioPlayer isPlaying])
{
    [self playPauseAudio];
}
if( iscommentOn==NO)
{
    [mCommentView hide];
    iscommentOn=YES;
}
else
{
     iscommentOn=NO;
        if(iscommentOn)
        if(![commentPlayer1 isPlaying])
          {
            iscommentOn=NO;
          }
        if(!iscommentOn)
          {
            iscommentOn=YES;
           if(mCommentView)
             {
                [commentPlayer1 stop];
                 commentPlayer1 = nil;
                [mCommentView hide];
                return;
            }
            float comx;
            float comy;
            if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
            {
                comx = 200;
                comy = 280;
            }
            else
            {
                comx = 50;
                comy = 170;
            }
            mCommentView = [[CommentUtility alloc] initWithFrame:CGRectMake(comx, comy, 330, 250)];
            [mCommentView setDelegate:(id)self];
            [self.view addSubview:mCommentView];
            [mCommentView show];
         }
      }
   }

What Change should I want to in my code, Any thing wrong with my code.
Please help me out.
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: UIView show and hide on click issue

    Hi Ankit,


    Try as following

    (IBAction)didTapFlag:(id)sender
    {
        int btnTag = ((UIButton *)sender).tag;
        if (btnTag == 0)
        {
            [yourView setHidden:YES];
            yourButton.tag = 1;
        }
        else
        {
            [yourView setHidden:NO];
            yourButton.tag = 0;
        }
    }

    I hope it helpful for you.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!