这是代码,我正在尝试使'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;
}
答案 0 :(得分:2)
您需要声明要使用self.viewController
@interface AppDelegate ()
-(Name *)createNameWithNonsenseDataWithIndex:(int)index;
@property (nonatomic, strong) ViewController *viewController;
@end
同样提及Haroldo Gondim
时,请确保您的笔尖名称正确无误。
从Xcode 4.4开始,您可以跳过
@synthesize
Declaration/definition of variables locations in ObjectiveC?
答案 1 :(得分:0)
在Nib
名称中,名称必须与.xib
文件的名称完全相同。
使用V大写。
self.viewController = [[ViewController alloc]
initWithNibName:@"ViewController" bundle:nil];
答案 2 :(得分:0)
“AppDelegate”类中没有属性“viewController”。 在接口声明下的AppDelegate.h中,您需要:
@property (nonatomic, strong) ViewController* viewController;
在您的AppDelegate.m实施声明中,您需要:
@synthesize viewController;