Links in NSTableView NSCell

I read and experimented with providing links in an NSCell user-defined frame over the last few days and basically did not get anything useful, there are always problems with each approach.

Does anyone know how to do this?

I use NSCell using - (void) drawInteriorWithFrame: (NSRect) theCellFrame inView: (NSView *) theControlViewm

NSCell is just a block with a variable height of text with links inside it, some cells have links, and some do not.

I tried using nsattributedstring with NSLinkAttributeName

I tried to intercept all the hits in the cell, and then tried to match them where they clicked, wherever the link was in the text, but which never worked.

I basically tried all the suggestions that I could find on all the boards, but most of the comments are old, so I hope someone comes up with a good way to do this.

Thanks David

+3
source share
1 answer

I have not tried this for sure, but I will try:

First, for hyperlinks, I use a category in NSAttributedString, akin to this post from Apple developer docs. The example here gives you the NSAttributedString hyperlinkFromString: withURL hyperlink method: `

Second, create a delegate for the table and implement the method tableView:willDisplayCell:forTableColumn:row:.

In this method

setAttributedStringValue:[NSAttributedString hyperlinkFromString:YOUR_STRING withURL:YOUR_URL]

or, if you need text without a hyperlink,

setAttributedStringValue:[SOME_NON_HYPERLINKED_STRING appendAttributedString:[NSAttributedString hyperlinkFromString:YOUR_STRING withURL:YOUR_URL]]

, NSCell, , NSTextFieldCell. , , , , . : , , . :

aCell aTableColumn, , .

from "http://developer.apple.com/library/mac/#documentation/ Cocoa/Reference/NSTableViewDelegate_Protocol/Reference/Reference.html" (, StackOverflow )

, .

-1

Source: https://habr.com/ru/post/1768110/


All Articles