UILabel转NSString加载webview

发布于 2024-11-28 18:56:51 字数 1049 浏览 1 评论 0原文

所以我有这段代码,我将变量storyLink发送到标签并将其显示在指定的笔尖中。到目前为止,标签显示的文本正是我想要的。但我想使用该文本作为网络视图的网址。 urlString = 现在什么都没有,因为我不知道如何使用/转换 UILabel 到适合 webview url 的字符串。因此,如果这基本上令人困惑,我想获取存储在标签中的文本并将其用作网络视图中的 url。有人可以帮忙吗?

TestView.h

@interface TestView : UIViewController {
    IBOutlet UILabel *label;
    IBOutlet UIWebView *webView;
    NSString *urlString;
}
@property(nonatomic, retain)IBOutlet UILabel *label;
@property(nonatomic, retain)IBOutlet UIWebView *webView;
@property(nonatomic, retain)NSString *urlString;

@end

TestView.m

- (void)viewDidLoad {
    [super viewDidLoad];
    label.text=nil;
    urlString=something;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];

}

发送代码

TestView *objFirstController=[[[TestView alloc] initWithNibName:@"TestView" bundle:nil] autorelease];
        [self.navigationController pushViewController:objFirstController animated:YES];
        objFirstController.label.text=storyLink;

So I have this code, where I am sending a variable storyLink to a label and display it in the specified nib. So far the label displays the text which is what I want. But I want to use that text as an url for a webview. urlString = nothing as of right now because I can't figure out how to use/convert an UILabel to a String suitable for a webview url. So if that was confusing basically I want to take the text stored in my label and use it for the url in my webview. Can someone help?

TestView.h

@interface TestView : UIViewController {
    IBOutlet UILabel *label;
    IBOutlet UIWebView *webView;
    NSString *urlString;
}
@property(nonatomic, retain)IBOutlet UILabel *label;
@property(nonatomic, retain)IBOutlet UIWebView *webView;
@property(nonatomic, retain)NSString *urlString;

@end

TestView.m

- (void)viewDidLoad {
    [super viewDidLoad];
    label.text=nil;
    urlString=something;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];

}

sending code

TestView *objFirstController=[[[TestView alloc] initWithNibName:@"TestView" bundle:nil] autorelease];
        [self.navigationController pushViewController:objFirstController animated:YES];
        objFirstController.label.text=storyLink;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花浅忆 2024-12-05 18:56:51

当设置在“viewDidLoad”期间访问的属性时,请确保将它们放在使用pushViewController之前。

TestView.m

- (void)viewDidLoad 
{
    [super viewDidLoad];
    label.text=urlString;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}

发送代码

TestView *objFirstController = [[[TestView alloc] initWithNibName:@"TestView" bundle:nil] autorelease];
objFirstController.urlString = storyLink;
[self.navigationController pushViewController:objFirstController animated:YES];

When setting properties that are accessed during 'viewDidLoad', make sure to put them before you use pushViewController.

TestView.m

- (void)viewDidLoad 
{
    [super viewDidLoad];
    label.text=urlString;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}

sending code

TestView *objFirstController = [[[TestView alloc] initWithNibName:@"TestView" bundle:nil] autorelease];
objFirstController.urlString = storyLink;
[self.navigationController pushViewController:objFirstController animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文