Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cea

macrumors newbie
Original poster
Oct 26, 2009
22
0
In the ImageBrowserCell.m, i tried to put the NSButton in a NSView container, then put it in a CALayer. The buttons appear as expected in each IKImageBrowerCell but they are not functional:

ImageBrowserCell.m:
PHP:
- (CALayer *) layerForType:(NSString*) type
{
--- snips ---
		//add a glossy overlay
		CALayer *glossyLayer = [CALayer layer];
		glossyLayer.frame = *(CGRect*) &relativeImageContainerFrame;
        
        NSView *container = [[[NSView alloc] initWithFrame:NSMakeRect(0,0,25,25)] autorelease];
        NSButton *button = [[[NSButton alloc] initWithFrame:NSMakeRect(0,0,25,25)] autorelease];
        [container addSubview:button];
        [button setImage:[NSImage imageNamed:@"pin.tiff"]];
        [button setTitle:@"BUTTON"];
        
        [container setLayer:layer];
        [container setWantsLayer:YES];
        [container addSubview:button];
        
		[glossyLayer setContents:container];
		[layer addSublayer:glossyLayer];

--- snip ---
}

Can anyone please help me?
 
Have you considered setting the button's action?
This is the issue. The IKImageBrowserCell creates the cells dynamically using CALayer code above, the cells are not even appear in the nib, so i cannnot set IBAction for buttons in the nib.
 
This is the issue. The IKImageBrowserCell creates the cells dynamically using CALayer code above, the cells are not even appear in the nib, so i cannnot set IBAction for buttons in the nib.

No one suggested that.

See the setAction: and setTarget: methods of the NSControl class. Since NSButton is a subclass of NSControl, it has those methods.
 
I added the setAction: and setTarget: methods and the Tooltip.
When i hold the mouse over the button for test, the tooltip for the container does not appear as expected, the same with the button. Click on the button does not happen anything.

ImageBrowserCell.m:
PHP:
- (CALayer *) layerForType:(NSString*) type
{
--- snips ---
        //add a glossy overlay
        CALayer *glossyLayer = [CALayer layer];
        glossyLayer.frame = *(CGRect*) &relativeImageContainerFrame;
        
        NSView *container = [[[NSView alloc] initWithFrame:NSMakeRect(0,0,25,25)] autorelease];
        NSButton *button = [[[NSButton alloc] initWithFrame:NSMakeRect(0,0,25,25)] autorelease];
        [container addSubview:button];
        [button setImage:[NSImage imageNamed:@"pin.tiff"]];
        [button setTitle:@"BUTTON"];
[button setAction:@selector(deleteMe:)];
 [button setTarget:self];
 //[button setToolTip:@"This is the button tooltip test."];
[container setToolTip:@"This is the container tooltip test."];
        
        [container setLayer:layer];
        [container setWantsLayer:YES];
        [container addSubview:button];
        
        [glossyLayer setContents:container];
        [layer addSublayer:glossyLayer];

--- snip ---
}

-(IBAction)deleteMe:(id)sender {
    NSLog(@"This is deleteMe.");
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.