0

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

AppDelegate.m

#import "AppDelegate.h"

#import "FirstViewController.h"

#import "SecondViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:        
goes on like normal app..........
@end

FirstViewController.h

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIImageView *bGround;

- (IBAction)settingsPressed:(id)sender;

- (IBAction)startPressed:(id)sender;

@end


@class SecondViewController;

@interface SecondViewController : UIViewController


@property(strong,nonatomic)SecondViewController *secondViewController;

@end

FirstViewController.m

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (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)settingsPressed:(id)sender {

この行には、「タイプ 'FirstViewController' のオブジェクトにプロパティ 'secondViewController' が見つかりません」と表示されています。これは、すぐ下の行です。

self.secondViewController =

[[SecondViewController alloc] initWithNibName:@"SecondViewController"
                                       bundle:nil];

下の行の最後の警告と同じ警告があります。

[self presentViewController:self.secondViewController animated:YES completion:nil];

}


- (IBAction)startPressed:(id)sender {
}
@end

SecondViewController.h

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController

@end

SecondViewController.m

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

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

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

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

@end
4

1 に答える 1

0

SecondViewController を 2 回宣言している理由がわかりません。FirstViewControler.h と独自の .h ファイルの両方でそうしているようです。とにかく、アクセスしようとしているプロパティをSecondViewControllerに与えたことが問題のようです。自分のコードを読み直してください:

@interface SecondViewController : UIViewController


@property(strong,nonatomic)SecondViewController *secondViewController;

@end

FirstViewController.h ファイルに必要なものは次のとおりです。

#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface FirstViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIImageView *bGround;
@property(strong,nonatomic)SecondViewController *secondViewController;

- (IBAction)settingsPressed:(id)sender;

- (IBAction)startPressed:(id)sender;

@end

.h ファイルの先頭で SecondViewController をインポートし、その @interface 内でプロパティを宣言していることに注意してください。

于 2013-07-10T22:54:56.270 に答える