I am getting 2 different images in place of splash screen - iphone

I am getting an different image at the start of the app like a splash screen then i am getting my actual image that i placed in coding.
I placed the splash screen with the following code in my didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.tabBarController;
self.tabBarController.delegate=self;
[window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
LoginViewController *vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
self.loginNav = [[UINavigationController alloc] initWithRootViewController:vc];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults valueForKey:#"UserName"] &&[userDefaults valueForKey:#"Password"])
{
vc.username=[userDefaults valueForKey:#"UserName"];
vc.password=[userDefaults valueForKey:#"Password"];
vc.autoLogin=YES;
[vc loginSelectorMethod];
}
else
{
[self.window addSubview:self.loginNav.view];
[self.window makeKeyAndVisible];
}
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:3.0];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSLog(#"Registering for remote notifications");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
Before the splash screen appears , the "Arrow.png" image appears then my splash screen appers.
If i delete the "Arrow.png" then in place of that image another images appears i.e., "aboutus.png" like that it continues.
I searched in my project for the "Arrow.png" it only appears once in my whole project in the coding.

here you add subiview as a tabbar like bellow..
[window addSubview:tabBarController.view];
after you add loginview like bellow..
[self.window addSubview:self.loginNav.view];
and after that you add splashscreen like bellow..
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
So this is the problem that you seen more then screen instead of splashscreen.
use bellow code...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:3.0];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSLog(#"Registering for remote notifications");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
and in removeSplash method add this view as a subview of window like bellow..
-(void)removeSplash{
[splashView removeFromSuperView];
LoginViewController *vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
self.loginNav = [[UINavigationController alloc] initWithRootViewController:vc];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults valueForKey:#"UserName"] &&[userDefaults valueForKey:#"Password"])
{
vc.username=[userDefaults valueForKey:#"UserName"];
vc.password=[userDefaults valueForKey:#"Password"];
vc.autoLogin=YES;
[vc loginSelectorMethod];
}
else
{
[self.window addSubview:self.loginNav.view];
[self.window makeKeyAndVisible];
}
}

Have you set any Launch image in ur project setting or have you put any image named "Default.png" in your project bundle this kind of image get detect by OS automatically while launch our app please check this 2 points.
edit:-
Than the problem is conflict in TabBar & LoginView & splaceImage.
For this do below stuff I thing this resolve your double image issue.
First, put below code in your DidFinishLaunching() method
//Delay second that how much time u show your splace image
int64_t delayInSeconds = 5.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//Do need Full like Add Login View or Add TabbBar
//Remove SplaceImageView From Window
});
splashView = [[UIImageView alloc] initWithFrame:self.window.frame];
splashView.image = [UIImage imageNamed:#"Default-Portrait~ipad.png"];
[self.window addSubview:splashView];
[self.window bringSubviewToFront:splashView];
return YES;
and also one more thing add default splace image like
for iPhone Portrait Default.png.
for iPad, Portrait Default-Portrait~ipad.png
follow as apple document for default image and then check.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.sql_ = [SQLDb initEngine];
[self setupControllers]; /// Set up Yor ToolBar Controller
self.hvController = [[HomeViewController alloc] init];
self.window.rootViewController = self.hvController;
[self.window makeKeyAndVisible];
[self setupSplash];
return YES;
}
-(void) setupSplash
{
self.imvSplash = [[UIImageView alloc] initWithFrame:self.window.bounds];
if( IS_IPHONE_5 )
[self.imvSplash setImage: [UIImage imageNamed:#"Default-568h#2x.png"]];
else
[self.imvSplash setImage: [UIImage imageNamed:#"splash.png"]];
[self.window addSubview: self.imvSplash];
[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:#selector(hideSplash:) userInfo:nil repeats:NO];
}
- (void)hideSplash:(NSTimer *)theTimer
{
[UIView animateWithDuration:1.0
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^{
self.imvSplash.alpha = 0.0;
self.ngNavigationController.view.alpha = 1.0;
}
completion:^(BOOL finished)
{
//[self.ngController setupImageAction];
[self.imvSplash removeFromSuperview];
}];
}

Related

How to move to another view without using a button

My first view displays an image and action indicator while web-servers and database function are run in that background. I want the application to go to my tab view when the functions have been completed. How do I do this?
Here is what the views look like.
What I have tried:
TabBarViewController *tab = [[TabBarViewController alloc]init];
[self presentViewController:tab animated:NO completion:nil];
and
[self performSegueWithIdentifier:#"first" sender:self];
Please can you help my to understand how to do this. I have spent many hours googling this problem and couldn't work out how to do it.
Thanks
EDIT: Added Code
Since you are downloading data you can get a call when the downloading request gets finished
like the method below
- (void)requestFinished:(ASIHTTPRequest *)request
and in this method you can very well present your TabBarViewController.
You can use GCD to make this happen.
For instance in your firstViewController where you trigger downloading you can do:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[model downloadData];
dispatch_sync(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:self];
});
});
I assume your downloadData method is synchronous, if not you can use notifications in your model. Once data is retrieved you could postNamedNotification from NSNotificationCenter and in firstViewController you could register for notification and after receiving it you would call performSegueWithIdentifier
You Can Declare A separate Method for that.
Call the below method when your function completes.
[self performSelector:#selector(gotonext:) withObject:nil afterDelay:4.0];
-(void)gotonext;
{
TabBarViewController *tab = [[TabBarViewController alloc]init];
[self presentViewController:tab animated:NO completion:nil];
}
Take one splashView Image at starting, like bellow...
#interface AppDelegate : UIResponder <UIApplicationDelegate>{
UIImageView *splashView;
}
#property (nonatomic, retain) UIImageView *splashView;
#end
in AppDelegate.m file...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
splashView = [[UIImageView alloc] initWithFrame:iphoneFrame];
splashView.image = [UIImage imageNamed:#"Default"];
[self.window addSubview:splashView];
[self.window makeKeyAndVisible];
UIViewController *viewController1 = [[[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil] autorelease];
UINavigationController *navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navviewController1.title = #"FirstTitle";
// navviewController1.navigationBarHidden=YES;
UIViewController *viewController2 = [[[yourviewController2 alloc] initWithNibName:#"yourviewController2" bundle:nil] autorelease];
UINavigationController *navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
// navviewController2.navigationBarHidden=YES;
navviewController2.title = #"SecondTitle";
UIViewController *viewController3 = [[[yourviewController3 alloc] initWithNibName:#"yourviewController2" bundle:nil] autorelease];
UINavigationController *navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
// navviewController3.navigationBarHidden=YES;
navviewController3.title = #"ThirdTitle";
//..... and so on depend on your requirement
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2 , navviewController3 ,nil];
[self performSelector:#selector(loadViewIphone) withObject:nil afterDelay:2.0];//**add this line at your all data are loading completed**
}
else
{
splashView = [[UIImageView alloc] initWithFrame:ipadFrame];
splashView.image = [UIImage imageNamed:#"Default_iPad"];
[self.window addSubview:splashView];
[self.window makeKeyAndVisible];
[self performSelector:#selector(loadViewIpad) withObject:nil afterDelay:2.0];
}
[self.window makeKeyAndVisible];
return YES;
}
-(void)loadViewIphone
{
[splashView removeFromSuperview];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFromBottom];
[animation setDuration:1.0];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:#"transitionViewAnimation"];
[self.window makeKeyAndVisible];
}
i hope this help you...
Hm... What if you put
TabBarViewController *tab = [[TabBarViewController alloc]init];
[self presentViewController:tab animated:NO completion:nil];
In
dispatch_async(dispatch_get_main_queue(), ^{
//stop the loader once the database stuff has finished and get rid of the text
[[self firstLoader]stopAnimating];
self.downloadingLabel.text = #"";
});
UPDATE: If you want to do this sync
dispatch_sync(a_queue, ^{ wait_for_me(); });
And after that present your VC.

Remove NavigaionBar In BCTabBar

i Tried To Make CustomTabBar With Animation Like BCTabBar
and I write this code in AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch. tabBarController.delegate = self;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[BCTabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:[[UINavigationController alloc]
initWithRootViewController:[[ProfileViewController alloc] init]], [[ChargeViewController alloc] init],
[[OffersViewController alloc] init],
[[ContactUsViewController alloc] init],
nil,nil];
[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
and It Works Fine But I wanna Remove NavigationBar In RootViewController What I Can Do ?
Cant you just hide Tabbar?
- (void)hideTabBar:(BCTabBarController *) tabbarcontroller
{
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[BCTabBarController class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
In ProfileViewController class write [[self navigationController] setNavigationBarHidden:YES animated:NO];. That should hide the navigation bar. If you need to show it anywhere else you can again set it as [[self navigationController] setNavigationBarHidden:NO animated:NO];

Open a Specific View controller when user launch UILocalNotification in ViewBased Application

I am working with UILocalNotification.Here When i Launch the notification i need a specific view in application.But I have tried like below coding .
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UIApplication sharedApplication]setStatusBarHidden:NO];
SplashView *mySplash = [[SplashView alloc] initWithImage:
[UIImage imageNamed:#"Splash.png"]];
[window insertSubview:mySplash atIndex:1];
[window makeKeyAndVisible];
mySplash.delay = 5;
mySplash.animation = SplashViewAnimationFade;
[mySplash startSplash];
[self.window insertSubview:viewController.view atIndex:0];
[self.window makeKeyAndVisible];
[mySplash release];
// Add the view controller's view to the window and display. [self.window addSubview:viewController.view];
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification)
{
NSLog(#"Notification Body: %#",localNotification.alertBody);
NSLog(#"%#", localNotification.userInfo);
}
[[UIApplication sharedApplication] cancelAllLocalNotifications];
application.applicationIconBadgeNumber = 0;
return YES;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
showItemContrller = [[Showitem alloc] initWithNibName:#"Showitem" bundle:nil];
[self.window addSubview:showItemContrller.view];
[self.window bringSubviewToFront:showItemContrller.view];
}
}
But When i launch the notification it is showing the previous view for fraction of seconds the it is going to showItemControllerView.
Thanking you
//comment this line....
//[self.window insertSubview:viewController.view atIndex:0];

Correct way to show Login Screen followed by UITabbarController menu

I need to implement the following and I wanted to know the correct way to do it.
when the iPhone application launches, I need to show a logo image for 2 seconds followed by showing a login screen that allows the person to login or create an account. Once the person logs in, i need to show a tabbarcontroller menu options.
This is how I'm currently doing it:
In the AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
LoginViewController *viewController0 = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController *aNavigationController0 = [[UINavigationController alloc] initWithRootViewController:viewController0];
self.window.rootViewController = aNavigationController0;
// I also implement an iVar of the UITabBarController here...
// ....
}
The #implementation:
#implementation LoginViewController
- (IBAction)createNewAccountButtonClicked:(id)sender {
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.window.rootViewController = delegate.tabBarController;
}
So, my questions are:
Is this the correct way to show the tabbar for my purpose?
In this scheme of things, I cannot show the logo animated. Any pointers on how to do this?
The code below assumes you're using ARC, if you're not then you'll need to do your MRC.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = self.tabBarController;
LoginViewController *loginViewController= [[LoginViewController alloc] initWithNibName:nil bundle:nil];
loginViewController.delegate = self;
UINavigationController *loginNavCont = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[self.tabBarController presentModalViewController:loginNavCont animated:NO];
UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default"]];
[self.window addSubview:splashScreen];
[UIView animateWithDuration:0.5
delay:2.0
options:0
animations:^{
splashScreen.alpha = 0.0;
}
completion:^(BOOL finished) {
[splashScreen removeFromSuperview];
}];
[self.window makeKeyAndVisible];
return YES;
}
- (void)loginViewControllerShouldBeDismissed:(UIViewController *)viewController
{
[self.tabBarController dismissModalViewControllerAnimated:YES];
}

How to switch from one UIViewController to another?

I have a problem with switching from one viewcontroller to another.
Here is what I have :
In my "AppDelegate_iPad.m" :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect frame = [UIScreen mainScreen].bounds;
window = [[UIWindow alloc] initWithFrame:frame];
window.backgroundColor = [UIColor blackColor];
LoginViewController_iPad *loginView = [[LoginViewController_iPad alloc] initWithNibName:#"LoginViewController_iPad" bundle:nil];
[window addSubview:loginView.view];
[self.window makeKeyAndVisible];
return YES;
}
That works. Now I have a login button on that screen and when pressed it calles this :
- (IBAction)doPressLoginButton
{
DebugLog(#"doPressLoginButton");
MenuViewController_iPad *menuView = [[MenuViewController_iPad alloc] initWithNibName:#"MenuViewController_iPad" bundle:nil];
[self.navigationController pushViewController:menuView animated:YES];
[menuView release];
}
The problem is that nothing happends. I assume I am missing the actual navigationconroller ?!
Hope that anyone can help.
Thank you
You should create a UINavigationController instance variable in your app delegate. Then, make sure you synthesize it and release it in your dealloc method.
Your implementation of application:didFinishLaunchingWithOptions: could look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// window is usually an IBOutlet
CGRect frame = [UIScreen mainScreen].bounds;
window = [[UIWindow alloc] initWithFrame:frame];
window.backgroundColor = [UIColor blackColor];
LoginViewController_iPad *loginView = [[LoginViewController_iPad alloc] initWithNibName:#"LoginViewController_iPad" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:loginView];
[loginView release];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
Now you'll be able to use self.navigationController.
I assume I am missing the actual navigationconroller ?!
you are right. :D
self.navigationController returns nil if you don't set up an NavigationController.
And any messages send to nil object will be ignored.
If you only need switch from one to another.
using
[self presentModalViewController:modalViewController animated:YES];
instead.