Programmatically switch view controller to show views in Tab Bar Controller - ios

I am trying to figure out how I can programmatically switch the views from one view controller to a first view controller in a Tab bar controller when I press a button.
Currently I have a view controller with three buttons. When I press a button I would like to then switch. This is the following code I have for this screen. It is called the second view controller.
import UIKit
class SecondViewController: UIViewController {
//Button Outlets
#IBOutlet var ButtonEndOfShift: UIButton!
#IBOutlet var ButtonMultiTimes: UIButton!
#IBOutlet var ButtonEndAndLunch: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//hides tab bar controller
self.tabBarController?.tabBar.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//Changes screen for End Of Shift Button
#IBAction func ChangeNextViewLow(sender: AnyObject) {
self.performSegueWithIdentifier("segue", sender: nil)
}
//Changes screen for Lunch and End Of Shift Button
#IBAction func ChangeNextViewMedium(sender: UIButton) {
}
//Changes screen for Multiple Times button
#IBAction func ChangeNextViewHigh(sender: UIButton) {
}
}

I have added UITabBarController in Storyboard like below please see images.
Then i have written following functions for your help.
// For navigate to Tabbar Controller
#IBAction func btnClick () {
self.performSegueWithIdentifier("GoToTabBar", sender: nil)
}
// For switching between tabs
func switchTab (index : Int) {
self.tabbarController.selectedIndex = index
}
You can also set UITabBarController as your application RootViewController.

Implement Code For didFinishLaunchingWithOptions
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
firstViewController *firstTab = [[firstViewController alloc] initWithNibName:#"firstViewController" bundle:nil];
UINavigationController *navCntrl1 = [[UINavigationController alloc] initWithRootViewController:firstTab];
secViewController *secTab = [[firstViewController alloc] initWithNibName:#"secViewController" bundle:nil];
UINavigationController *navCntrl2 = [[UINavigationController alloc] initWithRootViewController:secTab];
thirdViewController *thirdTab = [[thirdViewController alloc] initWithNibName:#"thirdViewController" bundle:nil];
UINavigationController *navCntrl3 = [[UINavigationController alloc] initWithRootViewController:thirdTab];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = #[navCntrl1, navCntrl2, navCntrl3];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];

Related

Open UIViewController upon clicking on UITabbarItem

I have created a UIViewController with a UITabbar in it.
I did not use UITabbarController because I wanted UITabbar on the top of the screen.
Upon clicking tab1, I want to present controller1 and on clicking tab2 I want to present controller 2. I don't want the tabbar to hide. I want to display the controller beneath the tabbar.
#interface MTLeaderFactoViewController () <UITabBarDelegate>
#property (weak, nonatomic) IBOutlet UITabBar *tabBar;
#end
#implementation MTLeaderFactoViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if (item.tag == 0) {
NSLog(#"item tag 0");
} else {
NSLog(#"item tag 1");
}
}
#end
My questions:
1) didSelectItem method is not triggered even after using UITabbarDelegate
2) What is the most elegant way of displaying the controller when clicked on a button? I don't want to use segue as all the controllers are in different storyboards.
For now, I plan to do
Controller1 *fp = [Controller1 controllerStoryboard:STORYBOARD_COURSE];
[self addChildViewController:fp];
[self.view addSubview:fp.view];
[fp didMoveToParentViewController:self];
EDIT 1:
Controller1 *fp = [Controller1 controllerStoryboard:STORYBOARD_COURSE];
[self addChildViewController:fp];
[self.view addSubview:fp.view];
[fp didMoveToParentViewController:self];
Tried this but it hides the tab bar. I want to utilize the space beneath the tab bar to display the controller
What you need to do is have a basecontroller class which will contain a tabbar(programatically created) then you can achive the desired output heres a sample baseController that i created,
import UIKit
class BaseViewController: UIViewController,UITabBarDelegate{
override func viewDidLoad() {
super.viewDidLoad()
let myTabBar = UITabBar()
myTabBar.frame = CGRect(x: 0, y: 60, width:self.view.frame.size.width, height: 50)
let one = UITabBarItem()
one.title = "one"
one.tag = 1
let two = UITabBarItem()
two.title = "two"
two.tag = 2
myTabBar.setItems([one,two], animated: false)
self.view.addSubview(myTabBar)
myTabBar.delegate = self
}
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
switch item.tag {
case 1:
let controller = storyboard?.instantiateViewController(withIdentifier: "SecondViewController")
addChildViewController(controller!)
view.addSubview((controller?.view)!)
controller?.didMove(toParentViewController: self)
break
case 2:
let controller = storyboard?.instantiateViewController(withIdentifier: "ViewController")
addChildViewController(controller!)
view.addSubview((controller?.view)!)
controller?.didMove(toParentViewController: self)
break
default:
break
}
}
}
View Controller class :
import UIKit
class ViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
SecondView Controller :
import UIKit
class SecondViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
I would suggest using UITabBarController instead of UIViewController.
Add UITabViewController in your StoryBoard name it FirstTabBarController.
Add child view controller to FirstTabBarController. In all your child view of add UITabbar. Connect the TabBar delegate to each of your child ViewController.
Hide the default TabBar in your default FirstTabBarController.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tabBar.isHidden = true;
[self setSelectedIndex:1];
}
Add action to TabBar in your child ViewController as
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSUInteger index = [[theTabBar items] indexOfObject:item];
NSLog(#"Tab index = %u", (int)indexO);
[self.navigationController.tabBarController setSelectedIndex:index];
}
I would prefer this method over manually adding adding or removing ViewController as subview, let the UITabBarController manage that for you. Do let me know if you have further queries.

Switch the sub viewController use segmented control

I want switch the sub view controller from the segment control.
There is vc1 and vc2 in the storyboard, and there is segment control on the main vc's navigation controller bar.
I want to add the vc1 and vc2 on the main vc, how to switch the sub vc use the segment controller?
How to do with that?
Follow below steps.
Add VC1 & VC2 as a childVC of mainVC.
On segment 1 selection VC1.view.hidden = false & vc2.view.hidden = true
On segment 2 selection VC2.view.hidden = false & vc1.view.hidden = true
take reference
How-to-add-childVC
How-tobind-segment-control-action
Code work
#IBAction func indexChanged(_ sender: AnyObject) {
switch segmentedControl.selectedSegmentIndex
{
case 0:
vc1.view.hidden = false
vc2.view.hidden = true
case 1:
vc2.view.hidden = false
vc1.view.hidden = true
default:
break
}
}
The accepted answer is obviously correct, but I honestly prefer using container view for each tab in UISegmentedControl. It that way the logic related with each view is separated in different view controller. You can achieve this in that way:
class TopViewController: UIViewController {
#IBOutlet weak var firstContainerView: UIView!
#IBOutlet weak var secondContainerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
firstContainerView.alpha = 1.0
secondContainerView.alpha = 0.0
}
#IBAction func didChangeIndex(_ sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
firstContainerView.alpha = 1.0
secondContainerView.alpha = 0.0
case 1:
firstContainerView.alpha = 0.0
secondContainerView.alpha = 1.0
default:
break
}
}
}
If you would like to access properties of FirstViewController or SecondViewController, you can implement prepare(for segue: UIStoryboardSegue, sender: Any?) method.
You should add vc, and the vc.view to the Main ViewController:
When you select the Segmented Control, you can hide the sub viewcontroller's view like below:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
_vc1 = [sb instantiateViewControllerWithIdentifier:#"ViewController1"];
_vc2 = [sb instantiateViewControllerWithIdentifier:#"ViewController2"];
[self addChildViewController:_vc1];
[self addChildViewController:_vc2];
[self.view addSubview:_vc1.view];
[self.view addSubview:_vc2.view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)segAction:(UISegmentedControl *)sender {
if (1 == sender.selectedSegmentIndex) {
NSLog(#"1");
_vc1.view.hidden = YES;
_vc2.view.hidden = NO;
}else {
NSLog(#"%ld", sender.selectedSegmentIndex);
_vc2.view.hidden = YES;
_vc1.view.hidden = NO;
}
}

How to make UIImage navigate to another ViewController?

Is it possible to make UIImage navigate to another ViewController when I tap on it ?
Just like UIButton.
Thanks.
ya you can use
var tap = UITapGestureRecognizer(target: self, action: Selector("imageCliecked"))
yourimageView.addGestureRecognizer(tap)
yourimageView.userInteractionEnabled = true // this is must dont forget to add
method is
func imageCliecked()
{
println("Tapped on Image")
// navigate to another
self.performSegueWithIdentifier("yoursegueName", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?)
{
if segue.identifier == "yoursegueName" {
var destViewController: ViewController = segue.destinationViewController as ViewController
destViewController.img = imageView.image // pass your imageview
}
}
another ViewController
class ViewController: UIViewController
{
strong var img: UIImage!
override function viewDidLoad()
{
if(self.img)
self.imageView.image = img;
}
}
UIImageView *imageView=[[UIImageView alloc]init];
//add gesture recogniser
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(navigate)];
tap.delegate=self;
[imageView addGestureRecognizer:tap];
//call method
-(void)navigate{
//call the navigation ..
}
For your question I have tried below solution.Also it works fine.
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var tapGesture = UITapGestureRecognizer(target: self, action: "navigationFromImage:")
tapGesture.numberOfTapsRequired = 1
imageviewNavigation.userInteractionEnabled = true
imageviewNavigation.addGestureRecognizer(tapGesture)
}
func navigationFromImage(sender: UIGestureRecognizer)
{
var secondViewController = storyboard?.instantiateViewControllerWithIdentifier("navigatingSecondViewController") as SecondViewController
secondViewController.globalImage = imageviewNavigation.image!
navigationController?.pushViewController(secondViewController, animated: true)
//OR
presentViewController(secondViewController, animated: true, completion: nil)
}
Also in Storyboard click the required view controller
1.Go to or click show the Identity inspector
2.Click Identity
3.In StorybordId you must give "navigatingSecondViewController" or whatever you want.
4.Finally you must give same name in your storyboard?.instantiateViewControllerWithIdentifier("navigatingSecondViewController")
in SecondViewController
var globalImage: UIImage = UIImage()
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view.
imageAccess.image = globalImage
}
yes it is possible to navigate one controller to another controller using property...
e.g.
// second Controller.....(you pass image on this controller)
#import <UIKit/UIKit.h>
#interface NewScreen : UITableViewController
{
}
#property(strong,nonatomic)UIImage *yourImage;
#end
/// First Controller where you pass your image...
- (IBAction)convertVideoButtonClicked:(id)sender
{
NewScreen *objNew=[self.storyboard instantiateViewControllerWithIdentifier:#"NewScreen"];
objNew.yourImage=imageNamed;
[self.navigationController pushViewController:objNew animated:YES];
// NSURL *videoPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"part1" ofType:#"mov"]];
// [self convertVideoToMP4:videoPath];
}

How to use SWRevealViewController with iPad SplitViewController

Hi I am using storyboard for my iPad app. How can I add SWRevealViewController to my app. I want to add slide view to my master view controller. Can any body please suggest me. I am loading my splitView using the following code in AppDelegate.h
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
DetailViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"CouponDetailRoot"];
Just make the Master View Controller the sw_front view of the SWRevealViewController. Then, if you want the detail view to be collapsed so only the master view shows up at first, create a class like this and assign it to the Master View Controller in storyboard:
import UIKit
class GlobalSplitViewController: UISplitViewController, UISplitViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
return true
}
}

Displaying splash screen for longer than default seconds

Is it possible to display the Default.png for a specified number of seconds? I have a client that wants the splash screen displayed for longer than its current time.
They would like it displayed for 2 - 3 seconds.
No, the default.png is shown while your app starts up.
You can add a new viewcontroller which will display the default.png in the application didFinishLoading.
This way you display the default.png a bit longer.
You should only show the default.png if you are loading data, which could take some time.
As the appstore guidelines state, you should not delay starting of you are any longer than necessary.
You can also use NSThread:
[NSThread sleepForTimeInterval:(NSTimeInterval)];
You can put this code in to first line of applicationDidFinishLaunching method.
For example, display default.png for 5 seconds.
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[NSThread sleepForTimeInterval:5.0];
}
This is super hacky. Don’t do this in production.
Add this to your application:didFinishLaunchingWithOptions::
Swift:
// Delay 1 second
RunLoop.current.run(until: Date(timeIntervalSinceNow: 1.0))
Objective C:
// Delay 1 second
[[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow: 1.0]];
If you are using the LaunchScreen.storyboard you can obtain the same view controller and present it: (remember to set the storyboard id, for example "LaunchScreen")
func applicationDidBecomeActive(application: UIApplication) {
let storyboard = UIStoryboard(name: "LaunchScreen", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("LaunchScreen")
self.window!.rootViewController!.presentViewController(vc, animated: false, completion: nil)
}
SWIFT 4
let storyboard = UIStoryboard(name: "LaunchScreen", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "LaunchScreen")
self.window!.rootViewController!.present(vc, animated: false, completion: nil)
In Xcode 6.1, Swift 1.0 to delay the launch screen:
Add the below statement in e didFinishLaunchingWithOptions meth in AppDelegateod
NSThread.sleepForTimeInterval(3)
Here, time can be passed based on your requirement.
SWIFT 5
Thread.sleep(forTimeInterval: 3)
Swift 3
This is doable in a safe way by presenting the splash controller for what ever time you specify then remove it and display your normal rootViewController.
First in LaunchingScreen.storyboard give your controller a StoryBoard identifier let's say "splashController"
In Main.storyboard give your initial viewController a StoryBoard identifier let's say "initController". -This could be nav or tab bar etc...-
In AppDelegate you can create these 2 methods:
private func extendSplashScreenPresentation(){
// Get a refernce to LaunchScreen.storyboard
let launchStoryBoard = UIStoryboard.init(name: "LaunchScreen", bundle: nil)
// Get the splash screen controller
let splashController = launchStoryBoard.instantiateViewController(withIdentifier: "splashController")
// Assign it to rootViewController
self.window?.rootViewController = splashController
self.window?.makeKeyAndVisible()
// Setup a timer to remove it after n seconds
Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(dismissSplashController), userInfo: nil, repeats: false)
}
2.
#objc private func dismissSplashController() {
// Get a refernce to Main.storyboard
let mainStoryBoard = UIStoryboard.init(name: "Main", bundle: nil)
// Get initial viewController
let initController = mainStoryBoard.instantiateViewController(withIdentifier: "initController")
// Assign it to rootViewController
self.window?.rootViewController = initController
self.window?.makeKeyAndVisible()
}
Now you call
self.extendSplashScreenPresentation()
in didFinishLaunchingWithOptions.
You are set to go...
This tutorial displays splash screen for 2 seconds. You can easily change it to suit your needs.
- (void)showSplash {
UIViewController *modalViewController = [[UIViewController alloc] init];
modalViewController.view = modelView;
[self presentModalViewController:modalViewController animated:NO];
[self performSelector:#selector(hideSplash) withObject:nil afterDelay:yourDelay];
}
This worked for me in Xcode 6.3.2, Swift 1.2 :
import UIKit
class ViewController: UIViewController
{
var splashScreen:UIImageView!
override func viewDidLoad()
{
super.viewDidLoad()
self.splashScreen = UIImageView(frame: self.view.frame)
self.splashScreen.image = UIImage(named: "Default.png")
self.view.addSubview(self.splashScreen)
var removeSplashScreen = NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: "removeSP", userInfo: nil, repeats: false)
}
func removeSP()
{
println(" REMOVE SP")
self.splashScreen.removeFromSuperview()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
}
ViewController is the first app VC that is being loaded.
In Swift 4.2
For Delay 1 second after default launch time...
Thread.sleep(forTimeInterval: 1)
Use following line in didFinishLaunchingWithOptions: delegate method:
[NSThread sleepForTimeInterval:5.0];
It will stop splash screen for 5.0 seconds.
Swift 2.0:
1)
// AppDelegate.swift
import UIKit
import Foundation
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var splashTimer:NSTimer?
var splashImageView:UIImageView?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIApplication.sharedApplication().delegate!.window!
let splashImage: UIImage = UIImage(named: "ic_120x120.png")!
splashImageView = UIImageView(image: splashImage)
splashImageView!.frame = CGRectMake(0, 0, (window?.frame.width)!, (window?.frame.height)!)
window!.addSubview(splashImageView!)
window!.makeKeyAndVisible()
//Adding splash Image as UIWindow's subview.
window!.bringSubviewToFront(window!.subviews[0])
// Here specify the timer.
splashTimer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "splashTimerForLoadingScreen", userInfo: nil, repeats: true)
return true
}
func splashTimerForLoadingScreen() {
splashImageView!.removeFromSuperview()
splashTimer!.invalidate()
}
2)
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
NSThread.sleepForTimeInterval(9)
OR
sleep(9)
return true
}
3) Using root view controller concept:
// AppDelegate.swift
import UIKit
import Foundation
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var splashTimer:NSTimer?
var storyboard:UIStoryboard?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()
storyboard = UIStoryboard(name: "Main", bundle: nil)
//Here set the splashScreen VC
let rootController = storyboard!.instantiateViewControllerWithIdentifier("secondVCID")
if let window = self.window {
window.rootViewController = rootController
}
//Set Timer
splashTimer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "splashTimerCrossedTimeLimit", userInfo: nil, repeats: true)
return true
}
func splashTimerCrossedTimeLimit(){
//Here change the root controller
let rootController = storyboard!.instantiateViewControllerWithIdentifier("firstVCID")
if let window = self.window {
window.rootViewController = rootController
}
splashTimer?.invalidate()
}
You can use following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSMutableString *path = [[NSMutableString alloc]init];
[path setString:[[NSBundle mainBundle] resourcePath]];
[path setString:[path stringByAppendingPathComponent:#"Default.png"]];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
[path release];
UIImageView *imageView=[[UIImageView alloc]initWithImage:image];
imageView.frame=CGRectMake(0, 0, 320, 480);
imageView.tag = 2;
[window addSubview:imageView];
[window makeKeyAndVisible];
// Here specify the time limit.
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:#selector(timerForLoadingScreen) userInfo:nil repeats:YES];
}
-(void)timerForLoadingScreen
{
[timer invalidate];
if ([window viewWithTag:2]!=nil)
{
[[window viewWithTag:2]removeFromSuperview];
}
// Your any other initialization code that you wish to have in didFinishLaunchingWithOptions
}
Put your default.png in a UIImageView full screen as a subview on the top of your main view thus covering your other UI. Set a timer to remove it after x seconds (possibly with effects) now showing your application.
The simplest way to achieve this is to creat an UIImageView with "Default.png" on the top of your first ViewController's UIView.
And add an Timer to remove the UIImageView after seconds you expected.
Write sleep(5.0)
in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions for 5 seconds splash screen will be displayed
This works...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Load Splash View Controller first
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"Splash"];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
// Load other stuff that requires time
// Now load the main View Controller that you want
}
1.Add a another view controller in “didFinishLaunchingWithOptions”
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *homeNav = [storyboard instantiateViewControllerWithIdentifier:#"NavigationControllerView"];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"SplashViewController"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = homeNav;
[self.window makeKeyAndVisible];
[(UINavigationController *)self.window.rootViewController pushViewController:viewController animated:NO];
}
2.In view did load of SplashView Controller
[self performSelector:#selector(removeSplashScreenAddViewController) withObject:nil afterDelay:2.0];
3.In removeSplashScreenAddViewController method you can add your main view controller for eg.-
- (void) removeSplashScreenAddViewController {` UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *homeNav = [storyboard instantiateViewControllerWithIdentifier:#"HomeNav"];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:viewControllerName];
UIWindow *window = [StaticHelper mainWindow];
window.rootViewController = homeNav;
[window makeKeyAndVisible];
[(UINavigationController *)window.rootViewController pushViewController:viewController animated:NO];`}
In swift 4.0
For Delay of 1 second after default launch time...
RunLoop.current.run(until: Date(timeIntervalSinceNow : 1.0))
You can simple specify number of seconds to sleep in the AppDelegate didFinishLaunchingWithOptions method.
Or alternatively use another ImageView to customize the splash screen.
See details for the latter at the following link by me:
Splash Screen Problem
Just go on project name. then Right Click/properties/Application Tab.
Find "view Application Events" near Slash form combobox.
copy this code in myApplication Class :
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
System.Threading.Thread.Sleep(3000) ' or other time
End Sub
You can create your own view and display it when application starts and hide it with timer. Please avoid delaying app start as its bad idea
The simplest solution here is to add sleep() to didFinishLaunchingWithOptions method in your AppDelegate class.
Swift 4:
sleep(1)
delays the LaunchScreen by 1 second.
If you wanna do something fancier you can also extend the current RunLoop in the same method:
Swift 4:
RunLoop.current.run(until: Date(timeIntervalSinceNow: 1))

Resources