Hyperlinks in an view-based TableView (NSTableCellView) - macos

I have an view-based TableView with an image and a NSTextField. I've got some links inside my NSTextField and I have tried many options (http://developer.apple.com/library/mac/#qa/qa2006/qa1487.html, dsclickableurltextfield) but nothing works out, because it seems that these options only fit to an cell-based tableview. I also watched the wwdc 2010 cocoa tips and tricks with an good explanation for links inside tableviews. But the custom NSTextFieldCell doesn't work for me. The mouse-events don't reach the custom class and for that reason nothings happens...
I hope you've got the right idea to solve this problem...

You need to add this to your table view's delegate:
- (BOOL)tableView:(NSTableView *)tableView shouldTrackCell:(NSCell *)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
return YES; // required for specific tracking control in our NSTextFieldCell
}

Related

Cannot edit fields in custom UITableViewCell (iOS 9)

after upgrading to iOS 9 (worked fine in iOS 8), I am having trouble clicking UIBUttons and editing UITextFields inside custom UITableViewCells.
I have an UITableView with custom UITableViewCells. These cells are loaded like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
controller=[[PresetRowViewController alloc] initWithNibName:#"PresetRowViewController" bundle:nil];
...
return (UITableViewCell *)controller.view;
}
The cells show fine, but I cannot click in any UIButton or edit any UITextField inside them.
Any ideas?
Thanks
Try checking for gesture recognizers (ie. view.gestureRecognizers = nil;) for various views (the button, cell itself). Also make sure button.userInteractionEnabled = YES; and cell.userInteractionEnabled = YES; Finally, make sure there's no invisible views overtop of the button/cell.
Try to bring the subviews in the customized table view cell to the front.
I had this same issue. Apple changed how UITableViewCells work in iOS 9. It was fixed for me by dragging in a new UITableViewCell into the Xib and moving everything over. See: https://stackoverflow.com/a/32826526/101923

Create Menu and SubMenu's in cocoa app

I am developing a cocoa app where i need to create Menu and Submenu's in my application.
I have attached a screenshot designed using flex. How can i do the same in cocoa.
Any help would be appreciated.
Thanks.
Your question itself is incomplete,though will try to match the solution your expecting…The screenshot you posted(you never mentioned the source of the screenshot you have taken,by analysing the design i edited in your question as “Flex”) looks like you don’t want to deal with NSMenuItem and NSMenu classes for the drop down menus…
Solution 1: Make a custom View(probably subview of NSView like popview) that handles input, displaying labels,imageviews etc.
==> Basically,both the menu bar and menu item are wrapped to an NSView And the drop down menu is wrapped to an NSPanel…Well as per the design you have to use NSView,because you will be able to add the corner you like and yes,there is a possibility of adding back ground colour as well…The menu item actually has subviews of NSTextView. If its a menu bar item then it only has one text subview for its title, and if its a sub menu item then it has 3 text subviews, one for the check mark, one for the title and one for the hot key list…No need to worry about the handling the events,the respective classes do their own event handling…It’s quite a complicated solution,but matches your requirement…
Found some example for you,check out this code which is in C++.
Solution 2: NSTableView with custom cell.Could be fugly, but maybe worth a shot.
==> Create a custom NSTableCellView/NSCell,with NSImageView(for icons like Pen), NSTextView(for the text “Pen Thickness”) and one more NSImageView(for the right corner icon) as it's subviews …You have to perform one of the two actions when user hits your cell…(1) If you would like to have the submenu,then again that cell should create one more NSTableView using the origin (cell.frame.origin.x+cell.frame.size.width, cell.frame.origin.y)…(2) If there is no submenu,perform the direct task...
Example: Assume "MenuItemCell" is the custom class name,in the delegate method tableView
willDisplayCell add the cell...
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
MenuItemCell *cell = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
result.imageView.image = //ur image
result.textView.setString//;
result.imageView.image = //corner image icon,if you would like to have submenu upon clicking this cell.
return result;
}
On selecting the custom cell,
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)rowIndex
{
NSLog(#"%i tapped!", rowIndex);
NSTableCellView *selectedRow = [tableView viewAtColumn:0 row:rowIndex makeIfNecessary:YES];
//if you would like to have the submenu,display one more NSTableView,based on the cell origin as i described above...don't forget to add the animation..
return YES;
}
Happy Coding.. :-)

Custom View-Based NSOutlineView disclosure?

Is there a simple way to customize the disclosure triangle for expandable items?
I tried removing it and calling [outlineView expandItem:X] when my custom disclosure indicator was clicked, but all the sexy built-in animations didn't work. Is there a trick to enable those animations? I tried [outlineView beginUpdates] but that yielded no results either.
Use the animator:
[[[outlineView] animator] expandItem:xyz]
use - (void)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item;

Cocoa - View-Based NSTableView, using one cell in multiple tables

I've got a problem. [for which the only example I can find was shown during one of the WWDC 2011 presentations ("Maximising Productivity in Xcode 4"), but there is no source available (it was an app called Birdathon). Everything else I come up with is for iOS, and doesn't translate across.]
Basically, I have some view-based NSTableViews, and currently lay out the image / text fields within my NSTableCellView directly in the column. I've got a subclass of NSTableCellView which gives me the outlets to assign values to each of the text fields I use within that cell. The DataSource and Delegate are implemented and working fine - the TableView with my custom NSTableViewCell works fine.
My problem is I'd like to use the same cell in multiple different tables. Rather than have to recreate the same layout each time, I feel I should be able to draw the NSTableCellView just once in IB. [- and indeed, the Birdathon example I mentioned seemed to show the NSTableCellView being laid out in it's own NIB.]
I've found the answer for iOS in many places, here for example: How do you load custom UITableViewCells from Xib files?
Can anyone help me modify that for Cocoa on Mac?
Thanks,
David
Like this!
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
return count;
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSView *customView = [tableView makeViewWithIdentifier:#"customview"
owner:self];
…… // set properties
return customView;
}
In interface builder, set the identifier of your custom cell view to "customview" and it will automagically be created! Example:
Just replace "Automatic" with the identifier you are using

cocoa + context sensitive menu on NSTableView with multiple rows selected

i am having a problem displaying context sensitive menu on control click on a tableview when multiple rows are selected.
Its working fine when a single row is selected and then control clicked on it.
The way i am implementing this is shown below:
-(void)doSingleClick
{
NSLog(#"single clicked");
if([[NSApp currentEvent] modifierFlags] & NSControlKeyMask)
{
NSLog(#"control clicked.......");
[NSMenu popUpContextMenu:[self showContextMenu] withEvent:[NSApp currentEvent] forView:tableView];
return;
}
}
and showContextMenu function returns a NSMenu object.
I am dong it this way as my table view for some strange reason does not recognize mouseDown or mouseUp or menuForEvent events.
the problem with the above code segment is, when multiple rows are selected and control clicked, it does not recognize the control click and does not go into that loop and hence not displaying the context menu.
Please suggest me a mechanism to achieve this.
Thanks
I don't recommend the approach that is given in the answers above. Instead, look at the "DragNDropOutlineView" example in Leopard and higher. That, and the release notes, give a proper way to implement contextual menus for a single row, or multiple rows. This includes having AppKit automatically do the proper highlighting.
corbin dunn
(NSTableView Software Engineer)
i hve tableviewcontroller class which is a subclass of NSTableView.
That's very bad naming and suggests that you are not architecting your application properly. Views aren't controllers. Keep them separate.
but this class in which i implemented menuForEvent method but its not getting called for some reason.
Did you make your table view an instance of this class in Interface Builder? If not, your instance is still an NSTableView, and the subclass you wrote is what Ian Hickson might call “a work of fiction”.
Corbin's answer is the best one here.
link text
I don't believe the action method is called when multiple rows are selected.
What would probably be a lot easier would be to override the menuForEvent: method in NSTableView. You'd have to create a subclass of NSTableView to do this, but it would be a cleaner solution.
You could also create an informal protocol (a category on NSObject) and have the NSTableView delegate return the appropriate menu.
#interface NSObject (NSCustomTableViewDelegate)
- (NSMenu *)tableView:(NSTableView *)tableView menuForEvent:(NSEvent *)event;
#end
#implementation NSObject (NSCustomTableViewDelegate)
- (NSMenu *)tableView:(NSTableView *)tableView menuForEvent:(NSEvent *)event {
return nil;
}
#end
And in your NSTableView subclass:
- (NSMenu *)menuForEvent:(NSEvent *)event {
return [[self delegate] tableView:self menuForEvent:event];
}

Resources