Pushing from ViewController to TabBarController takes delay - xcode

In my project, I have ViewController A for login, when I pressed the login button it show ViewController B where I have four buttons. When I click button1, I have showSegue direct to TabBarController and it has two tabs. Same as button 2,3,4 I have showSegue directs to NavigationController. Actually this is the hierarchy of my TabBarController and NavigationController:
Click Button 1 to:
TabBarController ->
Tab1 -> NavigationController -> ViewController1
Tab2 -> NavigationController -> ViewController2
Click Button 2,3,4 to:
NavigationController -> ViewController
I used storyboard in this project running Swift 2, Xcode 7. When I click each buttons, it takes almost 1-2 seconds delays especially on iPad real device. A bad user experience. It takes me a time to search some answers but sadly i didn't found a solution, that's why I asked it here..
Thanks in advance.

Maybe you should think about using an async method to load your controllers when you press the buttons.
Try to use
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
//Background Thread (Get your values - Run your requests)
dispatch_async(dispatch_get_main_queue(), {
//Update the UI (Give values to your outlets)
});
})

guys thanks for sharing your idea but i figured out the problems... Actually in my apps, I override one of navigation method which I changed the background of navigation bar with an image. The image is too large that's why it caused some delay before it present the next view. After changing the size of the image, it works properly now.

Related

Create Back Button with Storyboards

I currently have 3 tabs connected to a common UITabBarController. When one of the tabs is selected the user is taken to a UITableView with 3 cells which can be selected. When a cell is selected the user is taken to a new page with a UINavigationBar at the top. My understanding is that the UINavigationBar is supposed to include some sort of back button and I couldn't figure out how to enable it.
In place of the default back button, I dragged a UIButton to the corner and connected it to the 'Show Detail' property of the previous view but when I press the UIButton I am taken to the right UITableView but the tabs are missing for navigation. What am I doing wrong? My segues look like this:
The UINavigationController has the back functionality. How to go back one view in UINavigationController?.
Here is some old tutorial on how to combine that with a tabbarcontroller. should still be the same principles.

Standard Back Button in XCode (XIB)

I can't get the standard back button of iOS into a navigationBar because I can't find it in the Object Library, so can I do it with code or something else?
I just want the normal, standard, blue back button - you know which I mean.
To "automatically" have a back button you need first have a UINavigationController. Then you need to take a different UIViewController and add it as the root view controller in UINavigationController's init method:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:someOtherViewController];
Be sure to also set a title for someOtherViewController, usually in it's viewDidLoad or initializer. I'll tell you why this is important in a second:
self.title = #"Some other VC";
Then take a second UIViewController and push it onto your navigation controller:
[navigationController pushViewController:anotherViewController animated:YES];
You now have two UIViewControllers on your navigation stack: someOtherViewController and anotherViewController.
Your view will now have a back button with "Some other VC" in it. This is the title of the view controller that was just moved out of view:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
http://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/
I would also suggest reading up on how UINavigationControllers work and searching this site a bit more for customizing the back button. There are plenty of threads about it.
You can't add the back button yourself. The back button is part of the Navigation controller. If you embed a Navigation controller into your view(s), the back button will appear and be populated by the name of the previous view.
If you're using storyboards select your view controller, then in top menu choose "editor" -> "embed in" -> "navigation controller".
Edit: Here is an exmaple.
I'm running Xcode 7.2. This was driving me crazy, but I figured it out. Here are all the pieces you need to make the Back button appear (make a test project to prove it):
1) You have to have a Navigation Controller and it has to be set to be the initial view controller. So add the Navigation Controller, you will import two tables. Click on the Navigation Controller and on the properties list, check the box that reads "Is Initial View Controller". You will now see and arrow pointing to this view.
2) In our case we want a ViewController and not the included / connected TableViewController, so delete the TableViewController (RootController) and add a new ViewController.
3) Connect the Navigation Controller to the new ViewController by clicking on the top bar of the Navigation controller and orange circle with the arrow pointing left. Hold the Control button on your keyboard down and click and drag from the orange circle to the ViewController and let go. When given the list of options on how to connect the two views, select 'root view controller'.
Done! Now you the functioning navigation bar and you automatically get the back arrow on all segues added. Test this. Add another ViewController and connect to it with a button on the existing ViewController. Use the Control-click-drag approach from the button to the newest ViewController. Select the 'show' option for the new segue you created.
Run it. You'll see the back option has automatically appeared when you click the button and moved to the newest ViewController.
This is all provided by the Navigation Controller, but only when you make another controller the RootController. Happy navigating!

Does anyone know what the new Exit icon is used for when editing storyboards using Xcode 4.5?

Right-clicking the Exit icon yields an empty window. Can't Ctrl-drag a connection to any IB elements or corresponding source files. Docs give no love. Doesn't appear in nib files, only storyboards. My assumption is that it's a corollary to segues, but I don't see any new methods to back it up. Anyone?
I had a hard time following the accepted answer so here is more detail.
Given the photo below on view controller C you can "exit" back to any view controller in the segue path.
ViewController A you can write:
- (IBAction)done:(UIStoryboardSegue *)segue {
// Optional place to read data from closing controller
}
ViewController B you can write:
- (IBAction)back:(UIStoryboardSegue *)segue {
// Optional place to read data from closing controller
}
ViewController C you control drag from "back" button to the green exit option and select back:
ViewController C you control drag from "done" button to the green exit option and select done:
Note: Even though the methods are on other view controllers they show up for the ViewController C's exit. Control dragging and selecting a method defines which ViewController to unwind to.
There's a lot of information in the WWDC video "Session 407 - Adopting Storyboards in your App."
Say you have two view controllers linked by a segue. Implement the following exit action on the first view controller:
- (IBAction)done:(UIStoryboardSegue *)segue {
NSLog(#"Popping back to this view controller!");
// reset UI elements etc here
}
Then, on Storyboard scene for the second view controller, Ctrl-drag from a UI element, such as a button, to the exit icon at the bottom of this view controller. The done: action you added to the code of the first controller will appear as an option. Now, activating the button you Ctrl-dragged to the exit icon will pop back to the first view controller and maintain its original state (ie UI elements such as text input supposedly still intact).
As addition to Eric answer here is how it works with swift:
The function you add to the destination controller looks like:
#IBAction func backFromOtherController(segue: UIStoryboardSegue) {
NSLog("I'm back from other controller!")
}

Dismissing MWPhotoBrowser View controller Modally in Split View

Ran into a snag and hoping for some insight here.
Overview: Universal app. The iPhone portion works great. The iPad portion has a split view controller. The master is a table view (left side) where the user selects a row and displays its detail (right side). Pretty standard stuff.
I’m using Xcode version 4.4.1 and my project is using Core Data, Storyboards and ARC.
DetailViewController: On the detail is a button that brings up another table view (within the detail) of user notes by date with a custom view. Each note can have an image associated with it. If a note has an image then a button with its photo icon is shown.
Example screenshot up to this point:
MWPhotoBrowser: When the button of the photo icon is pressed I call MWPhotoBrowser (a wonderful library to show images in a standard way) to display the image or images. Single tap shows the one selected image, a double tap shows all images on the current table with the one chosen being viewed first. The image is displayed full screen.
To show the photo browser I use this code:
// Create the browser view.
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
// Set browser options.
browser.wantsFullScreenLayout = YES;
browser.displayActionButton = YES;
[browser setInitialPageIndex:self.buttonRow];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];
[self presentModalViewController:navController animated:YES];
The navController allows me to include a navigation controller with a “Done” button which calls doneButtonPressed.
Issue: All of the above works well until I press the “Done” button. The full screen photo browser dismisses properly. Unfortunately, the table view on the right side from where the user pressed the photo icon button is now gone (black). I thought the NotesViewController (right side) would remain there after photo browser was dismissed modally. Does calling a model view controller in a split view cause the other view controllers to be deleted?
Example screenshot showing problem:
The stacks on the detail view controller (right side) should be DetailViewController > NotesViewController > then call MWPhotoBrowser modally. After the photo browser is dismissed my self.navigationController.viewControllers.count equals 1 and I was expecting it to be 2.
Here’s the code that dismisses the MWPhotoBrowser:
- (void)doneButtonPressed:(id)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self dismissViewControllerAnimated:YES completion:nil];
}
.
.
.
Hope someone can help me wrap my head around this.
As always, any help is greatly appreciated. Thanks!
I resolved my issue within the NoteViewController (the area turning black after the MWPhotoBrowser was dismissed).
Within viewWillAppear I was setting my tableview to nil (to prevent cell overwrap) and reloading my table data.
self.tableView = nil;
[self.tableView reloadData];
This works fine for the iPhone and when not returning from the MWPhotoBrowser’s full screen display on the iPad. For some reason that I do not understand, the above code causes the issue. I added additional logic to check if I’m returning from the full screen display and now all is fine. I’ll look into it more when time permits.

xCode How to programmatically call UITabbar from a tab/subview/subclass using UIButton?

In my UITabbar Application (created using xCode) I have 6 tab buttons.
In the first tab I have 5 UIButttons which should load other 5 corresponding tabs when clicked on the buttons.
First one is the index/home page others are the different modules with a nib file for each of the modules.
My question is when clicked on the Button1 it should load tabbar 1(index's start from 0 for Tabbar App) and when clicked on the Button2 it should load tabbar 2 and so on.
In the IB action I have written the following code
-(IBAction)Button1:(id)sender
{
firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstView"bundle:nil];
[self.view addSubview:firstViewController.view];
}
To the best of my knowledge this paints(adds) the firstViewController on the tabbar 0 instead of calling the tabbar index 1.
Should I try
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
If so where should I write this?
Create a ParentTabbarController, which will derive from UITabBarController. Now place the subcontroller in this ParentTabBarController. Define a method in ParentTabBarController which will take care of placing the tab view in corresponding tabbar.
From your action on button tap you need to ping the parent controller method with the argument (may be index like 1,2 etc) which will place the tab on the basis of the provided index.
I hope this will help you identify the place to place the above mentioned code.

Resources