检查Bool值是否改变

时间:2016-04-27 16:09:24

标签: ios objective-c boolean observers

我想在我的Popover类中隐藏我的按钮,只要我在另一个类中的bool值为false,但问题是我没有得到" TRUE"值。

我的头等舱

SELECT Technician, Count(*) as '2016/17 Total',
SUM(CASE WHEN DATEPART (Month, InstallDate) = 04 THEN 1 ELSE 0 END) AS Apr,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 05 THEN 1 ELSE 0 END) AS May,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 06 THEN 1 ELSE 0 END) AS Jun,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 07 THEN 1 ELSE 0 END) AS Jul,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 08 THEN 1 ELSE 0 END) AS Aug,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 09 THEN 1 ELSE 0 END) AS Sep,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 10 THEN 1 ELSE 0 END) AS Oct,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 11 THEN 1 ELSE 0 END) AS Nov,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 12 THEN 1 ELSE 0 END) AS Dec,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 01 THEN 1 ELSE 0 END) AS Jan,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 02 THEN 1 ELSE 0 END) AS Feb,
SUM(CASE WHEN DATEPART (Month, InstallDate) = 03 THEN 1 ELSE 0 END) AS Mar
FROM Hardware_RefreshData
Where InstallDate between '2016-04-01' and '2017-03-31' 
GROUP BY Technician
ORDER BY Technician desc;

我在我的ViewWillAppear函数中调用了hideButton的方法。

我的第二课

 -(void) hideButton{
        finished = _secondVC.finished;
        BOOL isRunning = !finished;
        if(isRunning){
        _deleteButton.hidden = YES;
        }else if(finished){
            _deleteButton.hidden = NO;
        }
    }

编辑:

现在,如果我加载Popover并且NSNotification被触发,则启用该按钮,但问题是,如果我关闭并打开弹出窗口,我的删除按钮仍然被禁用。

我的PopOver类

-(void) someAction{
  if(something){
  self.finished = YES;
}

我的第二课

  - (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if(syncFinished){
          _deleteButton.enabled = YES;
    }else if(!syncFinished){
        _deleteButton.enabled = NO;
    }
}

    - (void)viewDidLoad {
      [super viewDidLoad];
      [[NSNotificationCenter defaultCenter] addObserver:self
                                                     selector:@selector(showButton)
                                                         name:@"syncFinish"
                                                       object:nil];
     }

    - (void) showButton{
     syncFinished = YES;
      _deleteButton.enabled = YES;
     }

2 个答案:

答案 0 :(得分:-1)

你不能直接观察价值。

您可以在操作开始/结束时发送NSNotification并在第一堂课中观察,以显示/隐藏按钮。

答案 1 :(得分:-1)

我用NSUserDefaults解决了这个问题。如果someAction正在发生,我可以设置bool。在其他所有课程中,我都可以阅读布尔。 所以在我的第二课:

 -(void) someAction{
       if(something){
         [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"syncFinish"];
        } else {
         [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"syncFinish"];
        }

在我的Popover课程中我说

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];

        if(![[NSUserDefaults standardUserDefaults] boolForKey:@"syncFinish"]) {
            _deleteButton.enabled = NO;
        } else {
            _deleteButton.enabled = YES;
        }
    }