gpt4 book ai didi

ios - TTTAttributedLabel Delegate didSelectLinkWithURL 在 iPhone 中没有被调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:29:12 41 4
gpt4 key购买 nike

这是我的代码,每当我单击链接时,didSelectLinkWithURL 委托(delegate)都不会被调用。感谢您的帮助。

    TTTAttributedLabel *tttLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *labelText = @"Lost? Learn more.";
tttLabel.text = labelText;
NSRange r = [labelText rangeOfString:@"Learn more"];
[tttLabel addLinkToURL:[NSURL URLWithString:@"action://show-help"] withRange:r];
[self.view addSubview:tttLabel];
tttLabel.userInteractionEnabled=YES;


- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {

UIWebView *web=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[web loadRequest:requestObj];
[self.view addSubview:web];

}

最佳答案

确保您的类实现了 TTTAttributedLabelProtocol,并设置 tttLabel.delegate = self;在头文件中:

@interface yourClass : parentClass <TTTAttributedLabelDelegate> {
}

在实现文件中

TTTAttributedLabel *tttLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];
tttLabel.delegate = self;
NSString *labelText = @"Lost? Learn more.";
tttLabel.text = labelText;
NSRange r = [labelText rangeOfString:@"Learn more"];
[tttLabel addLinkToURL:[NSURL URLWithString:@"action://show-help"] withRange:r];
[self.view addSubview:tttLabel];
tttLabel.userInteractionEnabled=YES;

- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
NSLog(@"Did click");
}

关于ios - TTTAttributedLabel Delegate didSelectLinkWithURL 在 iPhone 中没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20215965/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com