这是代码,我正在尝试使’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所提到的,确保你的笔尖名称是正确的.
Since Xcode 4.4 you can skip
@synthesize
Declaration/definition of variables locations in ObjectiveC?