所以我有这个代码,我将一个变量storyLink发送到标签并在指定的nib中显示它。到目前为止,标签显示了我想要的文本。但我想将该文本用作webview的URL。 urlString =现在没什么,因为我无法弄清楚如何使用/转换UILabel到适合webview网址的字符串。所以,如果那令人困惑,基本上我想把我的标签中存储的文本用于我的webview中的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;
答案 0 :(得分:0)
设置在'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];