1
votes

I'm setting up an NSTextView programmatically:

    NSTextView *infoTextView = [[NSTextView alloc] initWithFrame:insetRect];
[infoTextView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
    [infoTextView setBackgroundColor:[NSColor clearColor]];
    [infoTextView setTextContainerInset:NSZeroSize];
    [infoTextView setEditable:YES];
    [infoTextView setSelectable:YES];
    [infoTextView setAutomaticLinkDetectionEnabled:YES];

I'm targeting 10.6, and thought that automaticLinkDetectionEnabled meant that when the user typed a string that was a website address, NSTextView would format it blue color, underlined, and make it a clickable link. that doesn't happen. its just read as plain text. i have no formatting on the textView's textStorage.

the doc reads:

'Automatic link detection causes strings representing URLs typed in the view to be automatically made into links to those URLs.'

what else do i need to do?

2

2 Answers

3
votes

After the text is set do:

[infoTextView checkTextInDocument:nil];

This will go through all the text in the view and convert any url's to links at that point.

0
votes

answering my own question in case there is someone else on the planet who made the same mistake i did:

in a core data app, with a property 'notes', as in Entity.notes, if you set notes as binary type, and then use IB binding on an NSTextView for AttributedString binding, (do not use the Values binding), and use the built-in NSTransformer: NSKeyedUnarchiveFromData, the check boxes on the Inspector for Smart Links et al, work to setup the automatic link detection. you may do that programmatically as well.

i had my notes property as 'string', and also was binding to 'value'.

double d'oh.....