• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hyperlink in an NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Re: Hyperlink in an NSTableView (From: Greg Herlihy <email@hidden>)

  • Prev by Date: [Solved] Undo accidentally broken in Core Data app
  • Next by Date: Re: Subclassing a NSMutableArray
  • Previous by thread: Re: Hyperlink in an NSTableView
  • Next by thread: developing on Intel based mac for ppc
  • Index(es):
    • Date
    • Thread