UIBarButton项目在双击时起作用,并且在更改视图时也会更改状态

时间:2013-06-24 07:35:26

标签: iphone ipad title uitabbar

我有UIBarButto项目我希望当应用程序打开它应该说登录工作正常,当我点击登录时它不会在第一次点击时调用方法,但当我再次点击然后它工作,当视图改变,我们移动到另一个视图,并回到它应该是BarButtonItem Logout的标题,因为你有登录,你在另一个视图所以没有必要再次登录任何想法如何解决这个问题。我使用以下代码

感谢

    - (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];
    }

1 个答案:

答案 0 :(得分: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];
 }