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

第一视图控制器.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

第一视图控制器.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

第二视图控制器.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 感到困惑。您似乎在 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 回答