0

I have UIBarButto item i want that when app open it should say login which works fine and when i click on login it does not call method on first click but when i again click then it works and also when view is change and we move to another view and come back to this it should be title of BarButtonItem Logout becuase you have login and you are on the other view so no need to login again any idea how to fix this issue .I am using the following code

thanks

    - (void) loginPressed
{
   if (loginCheck)
   {
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)];
        popImageView.hidden=NO;
        passwordLabel.hidden=NO;
        userLabel.hidden=NO;
        userNameTextField.hidden=NO;
        userPasswordTextField.hidden=NO;
        signInButton.hidden=NO;
        tableView.hidden=YES;
      }
     else
     {
       self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)];
       popImageView.hidden=YES;
       passwordLabel.hidden=YES;
      userLabel.hidden=YES;
      userNameTextField.hidden=YES;
      serPasswordTextField.hidden=YES;
      signInButton.hidden=YES;
      tableView.hidden=NO;
   }

loginCheck = !loginCheck;
}


    - (void)viewWillAppear:(BOOL)animated
    {
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)];
    self.title=@"Activity";
    [super viewWillAppear:animated];
    }
4

1 回答 1

0

您的代码中有错误尝试使用它,我假设此代码用于测试,您应该更改登录检查而不是输入loginCheck = !loginCheck; 按照下面的代码,它将解决此代码的问题

- (void) loginPressed
{

if (loginCheck)
{

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)];

    popImageView.hidden=NO;
    passwordLabel.hidden=NO;
    userLabel.hidden=NO;
    userNameTextField.hidden=NO;
    userPasswordTextField.hidden=NO;
    signInButton.hidden=NO;

    tableView.hidden=YES;
} else {

   self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)];


 popImageView.hidden=YES;
 passwordLabel.hidden=YES;
 userLabel.hidden=YES;
 userNameTextField.hidden=YES;
 userPasswordTextField.hidden=YES;
 signInButton.hidden=YES;
 tableView.hidden=NO;

}

loginCheck = !loginCheck;     
}                                                                                             


- (void)viewWillAppear:(BOOL)animated
{


    if (loginCheck)
    {
      self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)];
    } else {
      self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Log out" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)];
    }

    self.title=@"Activity";


    [super viewWillAppear:animated];
 }
于 2013-06-24T07:48:29.977 回答