我正在使用 Xcode 4.6.2 并使用苹果模板创建了一个新的选项卡式应用程序。我在我的第一个视图控制器上放置了一个 UIWebView 并将http://google.co.uk加载到其中。在我的第二个视图控制器上,我创建了一个按钮,按下该按钮会将http://google.co.uk/images加载到第一个控制器上的 Web 视图中。这是我坚持的一点,到目前为止,这是我的代码:
第一视图控制器.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
IBOutlet UIWebView *mainWebView;
}
-(void)imagesURL;
@end
第一视图控制器.m
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"First", @"First");
self.tabBarItem.image = [UIImage imageNamed:@"first"];
}
return self;
}
- (void)viewDidLoad
{
[mainWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.co.uk"]]];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)imagesURL {
[mainWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.co.uk/images"]]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
SecondViewController.h
#import <UIKit/UIKit.h>
#import "FirstViewController.h"
@interface SecondViewController : UIViewController {
}
- (IBAction)imagesButton:(id)sender;
@end
第二视图控制器.m
#import "SecondViewController.h"
#import "FirstViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Second", @"Second");
self.tabBarItem.image = [UIImage imageNamed:@"second"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)imagesButton:(id)sender {
FirstViewController *view1 = [[FirstViewController alloc] init];
[view1 imagesURL];
}
@end
目前,当我按下第二个视图控制器上的图像按钮并切换回第一个时,什么也没有发生。网页无法加载。就像没有调用虚空一样。我究竟做错了什么?