Domanda

I'm trying to respond to link clicks on the TTStyledTextLabel.

I'm under the impression that I have to create a delegate for the TTNavigator because of what I've read on the internets.

I have this in my AppDelegate.cs

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
    _navigator = new TTNavigator();
    _navigator.Delegate = new NewsDelegate();
    _navigator.Window = Window;
    var map = _navigator.URLMap;
    map.FromToViewController("*",  (new MainController()).ClassHandle);
    return true;
}

But this is not responding to the News Delegate at all

    public class NewsDelegate : TTNavigatorDelegate
    {
        public override bool Navigator (TTNavigator navigator, NSUrl URL)
        {
            return false;
        }
    }

The breakpoint there is not triggering

È stato utile?

Soluzione

Ok this one drove me bonkers for quite some time. I tried a million things, subclassing the label, converting it to c#, etc etc. I finally found the solution.

You have to edit the bindings (I committed the change but it is not in there as of me writing it).

[BaseType (typeof (NSObject))]
interface TTNavigator
{
    [Static, Export("navigator")]
    TTNavigator Navigator {get;set;}
...

This static function allows you to access the global navigator. This will allow your delegate to fire. After you run the makefile and upload the new DLL (if it's not already in there).

Update your AppDelegate.cs

    public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
    {
        _navigator= TTNavigator.Navigator;
        _navigator.Delegate = new NewsDelegate();
        return true;
    }

Now your delegate will fire when a link is clicked

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top