gpt4 book ai didi

ios - webview 在 objective-c 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 06:15:17 29 4
gpt4 key购买 nike

我正在尝试根据我的数据库的内容加载一系列 url,即:http://www.whatever.com但是当我在模拟器中运行应用程序时什么也没有出现,我的代码如下所示

.h 文件(不包括导入语句)

@interface FSFourthScreenViewController : UIViewController

//insert code to create web view
{
NSString * urlString;
UIWebView * FSWebView;
}

// properties
@property (nonatomic, retain) NSString * urlString;
@property (nonatomic, retain) IBOutlet UIWebView * FSWebView;

@end

排除.m文件导入语句

@interface FSFourthScreenViewController ()

@end

@implementation FSFourthScreenViewController

@synthesize FSWebView, urlString;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

//background image
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundimage.png"]];

NSURL * url = [NSURL URLWithString:urlString];
NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];
[FSWebView loadRequest:requestObj];

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

我已正确连接 WebView ,并在数据库中分配了正确的字段。我还清理了 xCode 和模拟器,但仍然没有快乐......欢迎任何想法?

最佳答案

添加这段代码,检查你的对象:

  - (void)viewDidLoad
{
[super viewDidLoad];

//background image
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundimage.png"]];

NSURL * url = [NSURL URLWithString:urlString];

if (!url)
{
NSLog(@"url is nil!!!");
}


NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];

if (!FSWebView)
{
NSLog(@"RSWebView is nil!!!");
}

[FSWebView loadRequest:requestObj];

}

我猜 url 是 nil ,或者 webview 是 nil

关于ios - webview 在 objective-c 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22039927/

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