2

私はObjective -Cを使い始めたばかりです。私のコードはエラーを出し続けます: プロパティ 'view' がフォワード クラス オブジェクト 'startPageViewController' に見つかりません。私はそれが何であるかを解決することはできません! これが私のコードです。

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歳です。:)

4

2 に答える 2

4

The problem is the extraneous @class declarations in the startPageViewController.m file. Those are hiding the full definition you get from the #import statements.

You should only have @class forward declarations in a .h file (like you are already doing).

One other suggestion - It is standard practice in many programming languages, including Objective-C, that class names begin with an uppercase letter. Variables and method names should begin with lowercase letters. Doing this, along with everyone else, makes code easier to read.

于 2013-03-09T00:36:48.240 に答える
0

ヘッダーファイルをインクルードする場合は、転送宣言は必要ありません。したがって、以下を削除できます。

@class searchResultsViewController;
@class startPageViewController;
于 2013-03-08T21:55:29.987 に答える