Re: Hyperlink in an NSTableView
Re: Hyperlink in an NSTableView
- Subject: Re: Hyperlink in an NSTableView
- From: "Marcus S. Zarra" <email@hidden>
- Date: Thu, 16 Mar 2006 09:12:29 -0700
Thanks for the suggestion Greg, unfortunately it does not seem to be
working inside of an NSTableView. This is the method that I am using
which is based off of code written by Karelia. This is a category
method inside of NSString.
- (NSAttributedString *)hyperlink
{
NSMutableDictionary *dictionary = [NSMutableDictionary
dictionary];
[dictionary setValue:[NSNumber
numberWithInt:NSSingleUnderlineStyle]
forKey:NSUnderlineStyleAttributeName];
[dictionary setValue:self forKey:NSLinkAttributeName];
[dictionary setValue:[NSColor colorWithCalibratedRed:0.1 green:
0.1 blue:1.0 alpha:1.0] forKey:NSForegroundColorAttributeName];
[dictionary setValue:[NSCursor openHandCursor]
forKey:NSCursorAttributeName];
NSAttributedString *result = [[NSAttributedString alloc]
initWithString:self attributes:dictionary];
return [result autorelease];
}
The new addition was suggested by Greg, which is the
NSCursorAttributeName. That is the only portion of this that is not
working. When I hover over the field the cursor does not change
shape at all.
Currently I am not using a special cell in the NSTableView. I do
have the column bound inside of my window controller and in the -
awakeFromNib: method I setAllowsEditingTextAttributes to YES which
allows the underlining and blue color to show up.
Is there something I am missing to make the cursor change?
Marcus
On Mar 16, 2006, at 7:51 AM, Greg Herlihy wrote:
Assign the table an NSTextFieldCell as its dataCell class. For
content,
create an NSMutableAttributedString initialized with HTML text that
contains
a link. Lastly set the attributed string's cursor property to an arrow
cursor.
Something along the lines of:
NSString * htmlStr = @"<HTML><BODY><a href=\"http://
www.apple.com\">
my link</a></BODY></HTML>";
NSData * data = [htmlStr dataUsingEncoding:NSASCIIStringEncoding];
id s = [[[NSMutableAttributedString alloc] initWithHTML:data
documentAttributes:nil] autorelease];
[s addAttribute:NSCursorAttributeName value:[NSCursor arrowCursor]
range:NSMakeRange(0, [s length])];
Greg
On 3/15/06 3:25 PM, "Marcus S. Zarra" <email@hidden> wrote:
Is there an easy way to display a hyperlink in a NSTableView and have
it clickable and have the mouse over behave as expected?
Any tips would be greatly appreciated.
Marcus
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden