开发者

TTStyledTextLabel

I'm trying to get this control to work with a hypertext link with not much success. I have looked at TTCalaog and tried to replecate but does not work.

I have this working as far as displaying the hypertext link but it does not fire.

TTStyledTextLabel* label = [[[TTStyledTextLabel alloc] initWithFrame:CGRectMake(5, 0, 315, 175)] autorelease];

NSString* labelText = @"This should work";

label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];

[self.view addSubview:label];

I thing I am missing the point here perhaps with the placement of the google url? I have seen a post on this forum that makes use of custom-uri://some/url that is then set up in TTURLMap a开发者_如何学JAVAnd TTNavigator, but I need to open a url from the hypertext in a webview so I need the url to run a method in my class that creates my webview controller etc.

I have tried to cusomise TTURLMap to work without a TTNavigator but completely pickled?

Any help gratefullt appreciated ;-)

Thanks


I've just found myself a solution to catch the clicked URL on a TTStyledTextLabel. I hope this could help in your case too.

This's what I have done.

1. Create TTNavigator

    TTNavigator *navigator = [TTNavigator navigator];
    navigator.persistenceMode = TTNavigatorPersistenceModeNone;
    navigator.delegate = self;

2. Create TTNavigatorDelegate

As you assigned self as delegate of the navigator object. Therefore, please remember to add protocol in the header file .h before you continue.

In the implementation, create this method

    - (BOOL) navigator:(TTBaseNavigator *)navigator shouldOpenURL:(NSURL *)URL {
        // Now you can catch the clicked URL, and can do whatever with it
        // For Example: In my case, I take the query of the URL
        // If no query is available, let the app open the URL in Safari
        // If there's query, get its value and process within the app

        NSString *query = URL.query;

        if (query == nil) {
            return YES;
        } else {
            // process the query
        }
    }

I hope this helps! Please vote for me if this helps to solve your issue!

Best Regards,

Thang

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜