4

I've created a blank iPhone app project and would like to show a full-screen advertisement during app launch.

I tried to install the ad by following this guideline: https://github.com/mopub/mopub-ios-sdk/wiki/Interstitial-Integration-For-iOS

That's what I've done finally:

In ViewController.h

In ViewController.m

Actually all codes are just copied from the previous link.

However, an error shows when app runs:

Application windows are expected to have a root view controller at the end of application launch

I think this error may probably related to the loadView method, because if I remove the loadView method, the error disappeared.

In fact, this error seems common as it can be easily searched on the internet, but I don't know how loadView is related to it, and how can it be solved in my case.

Any solutions? Thanks a lot.

Kit Ng
  • 993
  • 4
  • 12
  • 24
  • Show the code in AppDelegate.m. Specifically the code in the application:didFinishLaunchingWithOptions: method. – Matt Tang Oct 06 '13 at 19:32

4 Answers4

7

You probably need to do this:

Add

#import "ViewController.h" 

to the top of AppDelegate.m

And in AppDelegate.m, your application:didFinishLaunchingWithOptions: method should have some code like this.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ... Other code

    // Override point for customization after application launch.
    ViewController *viewController = [[ViewController alloc] init];

    self.window.rootViewController = viewController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
Matt Tang
  • 1,297
  • 11
  • 17
2
UIViewController *vc = [[UIViewController alloc] init];

 [vc.view addSubview:self.tab_controller.view];

 [self.window setRootViewController:vc];

OR

UIViewController *vc = [[UIViewController alloc] init];

 [vc.view addSubview:yourClass.view];

 [self.window setRootViewController:vc];
TheCodingFrog
  • 3,406
  • 3
  • 21
  • 27
Ravi Nadendla
  • 103
  • 1
  • 3
1

If you started with an empty template and added a storyboard, you need to do a couple of things:

You need to delete all the lines (except return statement) inside didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
        return YES;
}

In project settings ->General, select your storyboard as the main interface

DHEERAJ
  • 1,478
  • 12
  • 32
0

Attached snapshot to help youenter image description here

At the right side check there is one option under attribute inspector which asks to set as "is rootView controller"

Sumit Kumar Saha
  • 799
  • 1
  • 12
  • 25