我刚开始使用Objective -C。我的代码不断给出错误:在转发类对象'startPageViewController'中找不到属性'view'。我无法弄清楚它是什么!这是我的代码。
startPageViewController.h -
#import <UIKit/UIKit.h>
@class searchResultsViewController;
@class startPageViewController;
@interface startPageViewController : UIViewController
- (IBAction)switchViews:(id)sender;
@property (strong, nonatomic) IBOutlet UITextField * searchterm;
@property (nonatomic, retain) startPageViewController *blueViewController;
@property (nonatomic, retain) searchResultsViewController *yellowViewController;
@end
startPageViewController.m -
#import "startPageViewController.h"
#import "searchResultsViewController.h"
@class searchResultsViewController;
@class startPageViewController;
@interface startPageViewController ()
@end
@implementation startPageViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)switchViews:(id)sender {
[self.view removeFromSuperview]; // <-- Error here
[self.view insertSubview:_yellowViewController.view atIndex:0];
}
- (void)viewDidUnload {
[self setSearchterm:nil];
[super viewDidUnload];
}
@end
searchResultsViewController.h -
#import <UIKit/UIKit.h>
@interface searchResultsViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIWebView *googleResults;
@property (strong, nonatomic) IBOutlet UIWebView *bingResults;
@property (strong, nonatomic) IBOutlet UIWebView *amazonResults;
@property (strong, nonatomic) IBOutlet UIWebView *ebayResults;
@end
searchResultsViewController.m -
#import "searchResultsViewController.h"
@interface searchResultsViewController ()
@end
@implementation searchResultsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *googleUrlAddress = @"http://www.google.com/";
NSURL *googleUrl = [NSURL URLWithString:googleUrlAddress];
NSURLRequest *googleRequestObj = [NSURLRequest requestWithURL:googleUrl];
[_googleResults loadRequest:googleRequestObj];
// --------------------
NSString *bingUrlAddress = @"http://www.bing.com/";
NSURL *bingUrl = [NSURL URLWithString:bingUrlAddress];
NSURLRequest *bingRequestObj = [NSURLRequest requestWithURL:bingUrl];
[_bingResults loadRequest:bingRequestObj];
// --------------------
NSString *amazonUrlAddress = @"http://www.amazon.com/";
NSURL *amazonUrl = [NSURL URLWithString:amazonUrlAddress];
NSURLRequest *amazonRequestObj = [NSURLRequest requestWithURL:amazonUrl];
[_amazonResults loadRequest:amazonRequestObj];
// --------------------
NSString *ebayUrlAddress = @"http://www.ebay.com/";
NSURL *ebayUrl = [NSURL URLWithString:ebayUrlAddress];
NSURLRequest *ebayRequestObj = [NSURLRequest requestWithURL:ebayUrl];
[_ebayResults loadRequest:ebayRequestObj];
}
- (void)viewDidUnload {
[self setGoogleResults:nil];
[self setBingResults:nil];
[self setAmazonResults:nil];
[self setEbayResults:nil];
[super viewDidUnload];
}
@end
提前致谢!
顺便说一句,请不要太复杂。我只有 12 岁。:)