【发布时间】:2013-07-09 01:35:45
【问题描述】:
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
【问题讨论】:
-
您从未将 secondViewController 声明为 FirstViewController 中的属性。
-
这家伙根本没有合成属性 secondviewController
标签: ios objective-c properties