how do i stop NSTextField blocking right clicks for NSTableView rows? - macos

As the title suggest, I've enabled right clicks for my tableview with customized rows. Anywhere there is an NSTextField, it blocks the right click.
is there a userInteractionEnabled equivalent for cocoa like on the iphone?

I though I probably needed to subclass everything in my NSTableCellView subclass, but I just needed to override -(NSView*)hitTest:(NSPoint)aPoint method in my NSTableCellView subclass to return self.

I'm able to right click on text fields within my custom view based table view cell. Here is how I configure it:
NSTextField *tf = [[NSTextField alloc] initWithFrame:NSZeroRect];
self.textField = tf;
self.imageView.autoresizingMask=NSViewWidthSizable;
self.textField.editable=NO;
self.textField.selectable=NO;
self.textField.drawsBackground=NO;
self.textField.bordered=NO;
self.textField.bezeled=NO;
self.textField.target=self;
self.textField.action=#selector(textDidEndEditing:);
[self.textField.cell setLineBreakMode:NSLineBreakByTruncatingMiddle];
Also, make sure you are setting the -menu property of NSTableView and not the cell view to enable to menu. (I don't know if that will make a difference to your issue but it is how I do right clicking in a table view.)

Related

Hand cursor not showing up for an NSButton added in a Model sheet

I have subclassed NSButton and created a class of my own, in which I have added the code to show up hand cursor when mouse pointer comes over the button. It's working for buttons that were added in normal views. But when I used the same class for a button inside a model sheet, cursor is not showing up. What might be the reason? Any idea!
This is the code I have added in NSButton subclass
- (void)resetCursorRects {
/*
* change cursor type to a poiting finger when it gets into HyperLink frame.
*/
[super resetCursorRects];
[self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]];
}
In Interface Builder, make sure your sheet's Window/Panel has Title Bar checked.
Since it's a sheet the title bar won't actually be visible, but for some reason cursor tracking seems to be disabled when this property is off.
Instand of Subclassing create a Category of NSButton. and override the
resetCursorRects method (same as the above).
#import the new Category to your controller and try.
if you not familiar with Category try this out.

Hiding and showing different scrollviews

So I have two scroll views that I want my XIB to show.
My first scroll view is loaded with the XIB and I want the second to be loaded when a button is pressed.
Does any body know how I can do this?
UIScrollView inherits from UIView. All you have to do is set it's hidden property to hidden. It is a simple set method. By default it will display as long as you add the view.
On your click action or method triggered simply set the property for the UIScrollView like:
[myScrollView setHidden:NO];
And if you want it to disappear again, on a different action:
[myScrollView setHidden:YES];

NSTableView selectable but not editable

Trying to get an NSTableView in IB to be selectable but not editable. But de-selecting "Editable" for a column also removes the selecting capability.
Can someone tell me where I should insert this code to make it work (not working in app delegate or window controller) :
NSTextFieldCell *aCell = [tableColumn dataCell];
[aCell setEditable: NO];
[aCell setSelectable: YES];
BTW that table is updated by dictionary bindings, and the dictionary controller is set to not editable.
Set the columns to Editable, but the individual cell behaviour to Selectable.
I'd try implementing tableView:shouldEditTableColumn:row:in your NSTableViews delegate and return NO. See here.

How to get NSTableCellView of view-based NSTableView?

I've just created my first view-based NSTableView in Interface Builder and I've correctly set up the data source and the bindings to update the views in the tableview. Each view has two labels and a NSProgressIndicator. Updating the progress indicator through the bindings and the data source works perfectly, but I'd like to change its state from determinate to indeterminate at some time. As my NSTableCellView subclass has access to the progress indicator, how can I get access to the cell view at a given row index? I've tried calling viewAtColumn:row:makeIfNecessary: on the tableview with both NO and YES for the makeIfNecessary argument, but neither seems to work.
Solution 1: In your NSTableCellView subclass add a property (IBOutlet) for your NSProgressIndicator control. Wire it in IB to set the property when the view is loaded. You can then access the progress control in your cell view subclass by using the property.
Solution 2: In IB give your NSProgressIndicator a unique integer tag. In your cell view subclass use [self viewWithTag:] to get the object.
I am not sure about the answer to your main question but you can bind the indeterminate state as well. In IB Is Indeterminate is listed in the Parameters section.

NSTextField : How to draw background only when focused

I put a textfield in a window, and I want the textfield draw background only when focused.
I know that all the controls in the window share one field editor.
I tried subclass nstextfield and implement becomeFirstResponder and resignFirstResponder.
And tried use custom singleton editor for the window .
Any one know how to achieve this?
In the NSWindow ,every textfield or button share one instance of field editor(a singleton NSTextView instance),so when you click the textfield, textfield become firstResponser first,and then quickly pass it to the shared field editor. So when the textfield lost focus ,the resignFirstResponder of the textfield will never be called(because the field editor is the FirstResponder now).
You can look at fieldEditor:forObject: in NSWindow API.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/occ/instm/NSWindow/fieldEditor:forObject:
SOLUTION:
(Thanks , Michael Gorbach)
In my window controller
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
{
NSText *text = [sender fieldEditor:YES forObject:self];
if(text&&[anObject isKindOfClass:[MyCustomTextField class]])
{
[text setBackgroundColor:[NSColor whiteColor]];
[text setDrawsBackground:YES];
}
return text;
}
I just did this recently, in a tableView. You need to use a custom cell and fieldEditor. Specifically, you need to call setDrawsbackground:YES on the NSText/NSTextView object that is the field editor, and setBackground: to configure your color of choice. There are two places to set up a custom field editor.
One is to implement setUpFieldEditorAttributes: on a custom NSTextFieldCell subclass that you have configured your NSTextField to use, and another is to use the window or window delegate method windowWillReturnFieldEditor:toObject:.
Note that if the first method doesn't work for a particular setting, sometimes you need to use the second, because it gets in earlier in the codepath.

Resources