Muhammad Umar
Muhammad Umar

Reputation: 11782

Loading new view shows blank screen in iphone

Please note that I am trying to learn iphone and for this problem, i can't figure out any solution.

I have created an empty view with the name of Loading. I have filled its Loading.xib with some images. Now this is the code I am using

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    Loading *firstView = [[Loading alloc]init];


    self.navigationController = [[UINavigationController alloc]init]; 
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    [self.navigationController pushViewController:firstView animated:YES];
    // Override point for customization after application launch.
    [self.window addSubview:self.navigationController.view];
    [window makeKeyAndVisible];
    return YES;
}

The problem is , when ever i run the code, it just shows the blank screen.

How can i load the loading screen. Any recommended tutorial links are welcomed

@implementation Loading

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

Best Regards

Upvotes: 0

Views: 2162

Answers (5)

angelokh
angelokh

Reputation: 9428

If someone found this thread, but still not able to figure it out. Try this. I forgot to add target membership for that view controller.

enter image description here

Upvotes: 0

dans3itz
dans3itz

Reputation: 1615

--> "Loading.xib" <--

You're never loading this, so unless the instance of "Loading"'s init: selector does some fancy stuff, this view is empty.

EDIT FOR: "can you explain a bit how can i call this? "

override init... *

- (id)init
{
    if ((self = [super initWithNibName:@"SomeNib" bundle:nil])) {
        // ...
    }

    return self;
}

* if the owner and nib don't match in IB, you either A) create the rationship properly in IB or B) do it manually in code:

update init:

[super initWithNibName:nil bundle:nil]

override:

- (void)loadView
{
    [super loadView];

    UINib *nib = [UINib nibWithNibName:@"SomeNib" bundle:nil];
    [nib instantiateWithOwner:self options:nil];
}

Upvotes: 1

danielbeard
danielbeard

Reputation: 9149

You need to load the view from its nib file. Here is an example:

Loading *firstView = [[Loading alloc] initWithNibName:@"Loading" bundle:nil];

Also, when you alloc your UINavigationController, you can set its root view controller property as well, rather than having to push the view like this:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: firstView];

Upvotes: 0

Selkie
Selkie

Reputation: 1783

First of all, Loading is a view not view controller. You shouldn't push it with navigation controller.

Secondly, it is not a good idea to add the navigation controller's view to the window.

Please check this thread for more detail about UIView and UIViewController

Instead, you may want to create a LoadingViewController, and change its view(XIB file) as what you want, then use code like this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
LoadingViewController *lvc= [[LoadingViewController alloc]init];

self.navigationController = [[UINavigationController alloc] initWithRootViewController:lvc]; 
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
// Override point for customization after application launch.
self.window.rootViewController = self.navigationController;
[window makeKeyAndVisible];
return YES;
}

Upvotes: 1

Mathew Varghese
Mathew Varghese

Reputation: 4527

You have to change the code like,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    Loading *firstView = [[Loading alloc] initWithNibName:@"Loading" bundle:nil];
    self.navigationController = [[UINavigationController alloc]init]; 
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    [self.window addSubview:self.navigationController.view];
    [window makeKeyAndVisible];
    [self.navigationController pushViewController:firstView animated:YES];
    return YES;
}

Hope that helps you.

Upvotes: 0

Related Questions