在不同的类中设置Bool [英] Setting Bool in different classes

查看:106
本文介绍了在不同的类中设置Bool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,其中后bool是真的,我想添加一个绘图到我的rect。这里是我有的代码,但由于某种原因,它是不是设置bool或调用setNeedsDisplay。我正确地引用其他类吗?感谢

I have the following code where after a bool is true I want to add a drawing to my rect. here is the code I have but for some reason it is either not setting the bool or calling the setNeedsDisplay. Am I referencing to the other class properly? thanks

//在AppController.m中

//in AppController.m

-(IBAction)colorToggle:(id)sender
{
    if ([colorFilter state] == NSOnState) 
    {
        CutoutView *theView = [[CutoutView alloc] init];
        [theView setFilterEnabled:YES];

    }

}

// in cutoutView.m

//in cutoutView.m

- (void)drawRect:(NSRect)dirtyRect
{
    [[[NSColor blackColor]colorWithAlphaComponent:0.9]set];
    NSRectFill(dirtyRect); 

    //this is what i want to be drawn when my bool is true and update the drawRect        
    if (filterEnabled == YES) {
        NSRectFillUsingOperation(NSMakeRect(100, 100, 300, 300), NSCompositeClear);
        [self update];
    }
}

-(void)update
{
    [self setNeedsDisplay:YES];
}


推荐答案

每个UILabel是一样的吗?喜欢,你可以从一个视图中删除一个UILabel,而其他所有的消失?嗯,你的CutoutView是一样的方式。当你写 CutoutView * theView = [[CutoutView alloc] init]; 那里,创建一个 CutoutView不显示在任何地方。您需要与您的现有 CutoutView(可能通过连接一个插座,但有很多完美有效的设计,将实现这一目标)。

OK, you know how not every UILabel is the same? Like, you can remove one UILabel from a view without all the others disappearing too? Well, your CutoutView is the same way. When you write CutoutView *theView = [[CutoutView alloc] init]; there, that creates a new CutoutView that isn't displayed anywhere. You need to talk to your existing CutoutView (probably by hooking up an outlet, but there are any number of perfectly valid designs that will accomplish this goal).

这篇关于在不同的类中设置Bool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆