Adding/removing rectangles from an NSImageView
Adding/removing rectangles from an NSImageView
- Subject: Adding/removing rectangles from an NSImageView
- From: Rob In der Maur <email@hidden>
- Date: Wed, 11 Feb 2004 21:55:26 +0100
Hi all,
I've searched the archives and found a lot of references to addSubView
and removeFromSuperView but nothing seems to solve my problem
I have a dialog in which I can press a button that will show a sheet
displaying an NSImageView amongst others. Based on the selection made
in the dialog I have to add rectangles to the NSImageView in the sheet.
So, in my -raisePageViewSheet action (the one that shows the sheet), I
create a couple of RectangleViews and put them on the NSImageView.
When closing the sheet I clean up the rectangles such that when the
sheet has to reappear with different rectangles, none of the old
rectangles is showing anymore. To do that, I look for the number of
subviews, go through them and call removeFromSuperView for each of
them.
The problem is that when the sheet reappears, the old rectangles still
show up. I simply can't get rid of them....
Relevant code from the -raisePageViewSheet:
for (i = 0; i < numberOfCaptions; i++) {
APECaption *caption = [[pageStyle captions] objectAtIndex:i];
NSLog(@"Dimension of caption %d is %@...", i, [caption data]);
RectangleView *rectView = [[RectangleView alloc]
initWithString
Data:[caption data]];
[pageViewImageView addSubview:rectView];
[rectView release]; // should release as adding to the subview did a
retain?
}
Relevant code from the -endPageViewSheet:
for (i = 0; i < [[pageViewImageView subviews] count]; i++) {
RectangleView *rectView = [[pageViewImageView subviews]
objectAtIndex:i];
[rectView removeFromSuperviewWithoutNeedingDisplay];
// tried [rectView removeFromSuperView] without effect
[pageViewImageView setNeedsDisplayInRect:[rectView bounds]];
}
Note: initWithStringData is a initialization routine in my NSView
subclass named RectangleView, which creates a rectangle based on string
data.
Anyone can tell me what I'm doing wrong?
cheers,
- Rob In der Maur
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.