UILabel转NSString加载webview
所以我有这段代码,我将变量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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当设置在“viewDidLoad”期间访问的属性时,请确保将它们放在使用pushViewController之前。
TestView.m
发送代码
When setting properties that are accessed during 'viewDidLoad', make sure to put them before you use pushViewController.
TestView.m
sending code