ios - 在 'viewController' 类型的对象上找不到属性 'AppDelegate'

标签 ios objective-c ios8 xcode6

这是代码,我试图让“self.viewController”工作,但它给我一个错误。我需要做什么来解决这个问题。我在该线程的标题中收到上述错误。

    #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 所述,请确保您的 Nib 名称正确。

Since Xcode 4.4 you can skip @synthesize

Declaration/definition of variables locations in ObjectiveC?

关于ios - 在 'viewController' 类型的对象上找不到属性 'AppDelegate',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31388806/

相关文章:

ios - [iOS][后台]更新 map 图钉 |画线

iOS ARKit + SceneKit 物理接触检测缩放问题

ios8 - Testflight iOS8 - 非 Apple ID 账户

iphone - Swift 中的同步代码执行

iOS 8 横向 : Keyboard does not display correctly

ios - 从 CTFramesetterRef 检索 NSAttributedString?

ios - 我需要从哪里下载应用商店连接的 dSYM?

ios - MagicalRecord 日期解析

iOS NSCoding NSMutableArray

objective-c - 如何修复警告 'no explicit ownership'