这是代码,我试图让“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/