I am trying to enumerate through all subviews of a view and create a snapshot image of each NSControl item and add it to a NSMutableArray. The ultimate goal is to allow a user to rearrange the various UI elements.
I have subclassed NSView and added two properties:
In IB, I added two TextViews to the main view and set the class of the view to MyContent.
Then, in the MyContent implementation, I have the following, in awakeFromNib:
Using various NSLog statements, it seems that the subViewObjects are correctly added to an array, but the subViewImages array does not get populated with images. I am convinced I have overlooked something really simple and it is driving me crazy! Does anybody know what I am doing wrong?
I am using Xcode 4.2.1, with ARC and Lion (10.7.2)
If anybody can point me in the right direction, I would be very grateful
I have subclassed NSView and added two properties:
Code:
@interface MyContent : NSView
@property (strong) NSMutableArray *subViewObjects;
@property (strong) NSMutableArray *subViewImages;
@end
In IB, I added two TextViews to the main view and set the class of the view to MyContent.
Then, in the MyContent implementation, I have the following, in awakeFromNib:
Code:
// Copy all the items on the view
subViewObjects = [[self subviews] mutableCopy];
NSLog(@"%@",subViewObjects);
// Create images of all the views
NSUInteger i, count;
for (i = 0, count = [subViewObjects count]; i < count; i++) {
NSView *view = [subViewObjects objectAtIndex:i];
NSImage *image = [[NSImage alloc] initWithSize:[view bounds].size];
[image lockFocus];
[view drawRect:[view bounds]];
[image unlockFocus];
[subViewImages addObject:image];
NSLog(@"Number of subViewImages; %lu",[subViewImages count]);
}
Using various NSLog statements, it seems that the subViewObjects are correctly added to an array, but the subViewImages array does not get populated with images. I am convinced I have overlooked something really simple and it is driving me crazy! Does anybody know what I am doing wrong?
I am using Xcode 4.2.1, with ARC and Lion (10.7.2)
If anybody can point me in the right direction, I would be very grateful
Last edited: