4

This is the code, i'm trying to make the 'self.viewController' work, but it is giving me an error. What do i need to do to fix this. I am getting the error as stated above in the header of this thread.

    #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;


    }
Divine Davis
  • 532
  • 1
  • 6
  • 15

3 Answers3

2

You need to declare a property to use self.viewController

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

Also as Haroldo Gondim mentioned make sure the name of your nib is correct.

Since Xcode 4.4 you can skip @synthesize

Declaration/definition of variables locations in ObjectiveC?

Community
  • 1
  • 1
Alaeddine
  • 6,104
  • 3
  • 28
  • 45
  • also you can just call init, as long as the xib has the same name as the view controller class `self.viewController = [[ViewController alloc]init];` – Alaeddine Jul 15 '15 at 02:36
0

In Nib name the name must be exactly the name of your .xib File. Use V with upper case.

self.viewController = [[ViewController alloc]        
initWithNibName:@"ViewController" bundle:nil];
Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62
0

There is no property 'viewController' in your 'AppDelegate' class. In your AppDelegate.h under interface declaration you need to have:

@property (nonatomic, strong) ViewController* viewController;

And In your AppDelegate.m under implementation declaration you need to have:

@synthesize viewController;
SanitLee
  • 1,253
  • 1
  • 12
  • 29