On 2012-10-25, at 5:40 PM, Mike Abdullah wrote:
> Presumably your NSView subclass implements -drawRect:
Yes my sub-class does implement -drawRect

> Is this being called at all for you non-drawing view?
Yes. Let's refer to the sub-class instances as 1st and 2nd
1st is the one I created first using IB (dragging Object and making the class 
my sub-class view)
2nd is the one I created yesterday the same way.

When the app is first launched a window is created and drawn correctly. The 
sequence is as follows:
In my sub-class these methods are called in this order 
2nd -initWithFrame  (which has [self setNeedsDisplay:YES]; as the last 
statement.
1st -initWithFrame
1st -drawRect
2nd -drawRect

Now if I Cmd+N or use the File New menu item a second window is created and the 
sequence is the same.
Except that the 2nd instance is not drawn in the window (content area).
This is true thereafter for every New invocation.

> If it is being called, is there anything weird about the view or environment 
> at the time?
Well there must be but this is pretty vanilla stuff. 
The MainMenu.nib is exactly as is from the template.
The Document.nib has these two sub-class instances plus 3 colorWells with 
labels.
These are hooked up to set the Start & Stop gradient colours and the interior 
face colour of each instance.
This all works for the initial window.

> What triggers do you have to cause the view to be redrawn?
Other than the above initializations only clicking on the colorWells.

BUT I just found something bizarre thanks to your stimulation.
Consider the following:
Launch the app - first window appears.
Click on colorWell and choose a colour and click.
The colour is effected on both instances (1st and 2nd)

Next do a File/New and a second window appears but without 2nd instance drawn.
In second window click on colorWell and choose a colour and click.
THIS is effected on the 1st instance in the second window BUT the 2nd instance 
in FIRST window.

How can this be? All I did was use IB to make a 2nd instance of my sub-class 
and positioned it.
Where do I go from here?

My code in Document.h/.m 
@property (weak) IBOutlet MakeIcon *normalView;
@property (weak) IBOutlet MakeIcon *pushedView; 
- (IBAction)startColor:(NSColorWell *)sender;

-(void) startColor:(NSColorWell *)sender{
    [normalView changeStartColor:startColorWell];
    [pushedView changeStartColor:startColorWell];
}

My code in the sub-class .m
- (void)setStartColor:color{
    startColor = color;
    [self setNeedsDisplay:YES];
}
-(void)changeStartColor:(NSColorWell *)sender{
    [self setStartColor:[sender color]];
}


> On 25 Oct 2012, at 21:16, Peter Teeson <ptee...@me.com> wrote:
>> Xcode 4.5.1 Lion 10.7.4
>> I have desktop Document project with a sub-class of NSView. Debug only 
>> version as of now.
>> The Window has 2 instances of this sub-class (basically squares that have 
>> gradients);
>> The only difference between the two instances are the start and stop mid 
>> points for the gradients.
>> 
>> When I Run it to debug, a Document window opens and behaves as I expect.
>> In particular both instances of the sub-class are drawn in the window.
>> 
>> The Problem:
>> But when I Cmd + N to get a new document then only one of the sub-class 
>> objects is drawn.
>> The one that is not drawn is the second instance I added yesterday.
>> As I said the only difference between the two instances is the value of an 
>> ivar (which I set 
>> appropriately in Document.m awakeFromNib.)
>> 
>> My efforts to track this down have failed and I lack understanding how this 
>> could happen.
>> After all they are using the same nib (xib). And indeed the value of each 
>> pointer to the instances
>> are not zero. And the various ivars are correctly initialized.
>> 
>> The Questions:
>> How could this happen? How can I try to track it down?
>> 
>> TIA & respect…
>> Peter
>> 
>> P.S. I first posted this to the Xcode list but was advised to post here 
>> instead.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to