属性 'viewController' 未在类型 'AppDelegate' 的 object 上找到

Property 'viewController' not found on object of type 'AppDelegate'

这是代码,我正在尝试使 'self.viewController' 正常工作,但它给我一个错误。我需要做什么来解决这个问题。我在该线程的 header 中收到上述错误。

    #import "AppDelegate.h"
    #import "ViewController.h"
    #import "Name.h"

    @interface AppDelegate ()

    -(Name *)createNameWithNonsenseDataWithIndex:(int)index;


    @end

    @implementation AppDelegate

    @synthesize tableData;



    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        return YES;

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        //Create dummy data

        NSUInteger numberOfNames = 25;

        self.tableData = [[NSMutableArray alloc] initWithCapacity:numberOfNames];

        //Create a temporary array of tableData
        for (NSUInteger i = 0; i < numberOfNames; i++) {
            //Create a new name with nonsense data
            Name *tempName = [self createNameWithNonsenseDataWithIndex:1];

            //Add it to the temporary array
            [self.tableData addObject:tempName];

        }

        self.viewController = [[ViewController alloc]        
    initWithNibName:@"viewController" bundle:nil];


        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;


    }

您需要声明一个 属性 才能使用 self.viewController

@interface AppDelegate () 
   -(Name *)createNameWithNonsenseDataWithIndex:(int)index;
    @property (nonatomic, strong) ViewController *viewController; 
@end

也如Haroldo Gondim所述,确保笔尖名称正确。

Since Xcode 4.4 you can skip @synthesize

Declaration/definition of variables locations in ObjectiveC?

Nib 名称中,名称必须与您的 .xib 文件的名称完全相同。 使用大写字母 V。

self.viewController = [[ViewController alloc]        
initWithNibName:@"ViewController" bundle:nil];

你的'AppDelegate'class中没有属性'viewController'。 在您的 AppDelegate.h 接口声明下,您需要:

@property (nonatomic, strong) ViewController* viewController;

并且在您的 AppDelegate.m 实施声明中,您需要:

@synthesize viewController;