I am trying to create a ver simple app in iOS 7. In this I need move back and forward using UIBarButtonItem. But when I am pressing back button it is loading a view but not showing all UI Controls properly basically the view is empty. in the below as I pressed any of the cell it will move to another view and load respective data.
On the pressing back button it should show earlier image but it is showing following view.
Please tell me where I am going wrong Thanks in advance.
It seems as if your second screen is presented modally. Then you need to make an unwind segue.
Add this code to the viewcontroller that should be returned to:
-(IBAction)backButtonUnwindSegue:(UIStoryboardSegue *)segue
{
}
then from your modal vc, in storyboard. Drag a segue from the "Back"-button to the Green "Exit"-icon and select the backButtonUnwindSegue-action
Check Out this:
Passing Data example
Related
How do I create a custom back button on one of my storyboards, when I do a segue and I say push it creates a back button on Mac with but when I do a modal or model it does not create a back button?
Modally presented view controllers do not automatically get close buttons.
self.navigationController.leftBarButtonItem = ...
A pushed view controller will automatically create a back button if the navigation controller is shown.
You will have to create your own back button. In the view controller that you have presented via the modal transition, you have to put a toolbar on it. Put it at the top and if using autolayout set the constraints top, both sides and height. Then place a barbuttonitem in the toolbar. You can select a system button like done or cancel. Make sure the new view controller is the class that you created. Now you can control drag from the barbuttonitem to your .h file and connect an IBAction. Call it dismiss or something like that. In that method call [self dismiss viewcontroller:animated completion:nil]. This will bring you back to the original view controller. I am not a my computer right now so I am not sure the exact wording of the dismiss method, but it will auto fill for you. Good luck.
As Douglas explained, you need to create property of the button (UIButton or BarButtonItem) and in the viewcontroller .m file connect
- (IBAction)backButton:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
with the button. This will dismiss the current view controller and bring you back to the previous one :)
In my app, I would like a loading screen which has a start button, and when the user presses the start button, it displays my the actual parts of my application.
I can't use a Default.png because i need the functionality of the start button. And since my rootViewController is a tabBar, I can't simply add my screen as a subview, because then my loading screen just appears in each individual tab.
Any ideas?
You could create a new view controller and set that view controller as the root view controller. In the new view controller, create a UIImageView with the loading image and a UIButton where you want it. Then you could go in the storyboards and make the button transition to the "actual parts of [your] application".
Hope this helps!
There are several ways to do it. Assuming your app spends very little time in the Start Screen, I would implement it as a modal view controller that I display over the root tab view.
After you load your root tab bar view for the first time, present the Start Screen view controller without animations.
[tabBarViewController presentViewController:startViewController animated:NO completion:NULL];
If you do this early enough (e.g., in your app delegate's didFinishLaunching: method), the start screen will be the first thing the user sees. It's hard to say exactly where you should insert this code since you haven't said whether you are using storyboards or a default nib or loading a view manually etc.
When the button is pressed, simply dismiss the startViewController.
I've set up a really simple project using storyboards including two views as shown here: http://i.stack.imgur.com/iRx21.png. The navigation can be done by either selecting a cell in the custom table view or hitting the back button labelled with "<<". Everything works fine except the following:
when I switch between the views, every time an instantiation happens. The profiling shows an increasing number of view objects. I would like to keep only one of each view and instantiation should be happen only once. What am I doing wrong? (I'm using ARC.)
Thanks in advance!
You should not link your back button to the parent view controller. This is what causes the new instantiation.
The way to go is to embed the table view into UINavigationController (in IB, choose Editor -> Imbed In -> Navigation Controller. Then change your segue to a Push segue. You can of course hide the navigation bar etc. to make things look exactly as you like. Then, link the back button to the controller with an IBAction and in the handler do a simple
[self.navigationController popViewControllerAnimated:YES];
This would be the appropriate logic of what you are doing. Of course, you can also push the web view modally and then handle the button click with
[self dismissModalViewControllerAnimated:YES];
My iOS/iPhone app starts with a login page (a little like the login page on the Facebook app). There's an info button at the bottom that flips the first view controller onto another that gives a little info about the app to anyone before they login.
What I'm struggling with is that I'm using a UIWebView to display my few paragraphs of body text and a picture, however it's contents is filled in on 'viewDidLoad'. This means that momentarily when I'm 'flipping' between the ViewControllers the info page is blank and only gets filled with my content when the animation is complete.
I have tried setting up the UIWebView inside initWithCoder:(NSCoder *)aDecoder with no luck.
Does anyone have any idea how to render it/have it ready for when it is visible? It looks fine if I leave it and then flip back.
Thanks!
you can "force" the call of the viewDidLoad of the second ViewController in the first with:
[secondViewController view];
with this you can avoid to wait for loading the webview
If I understand this correctly, why not render the second view when the app loads or in the background after the first VC loads and have it hidden, then make it visible it when the user presses the button?
Or maybe just render the webview in the first view controller then pass it to the second view controller when the user presses the button.
Have you tried using the option UIViewAnimationOptionAllowAnimatedContent for the flip animation?
I have 2 tabbars in my tabbar controller. I am currently in the second tabbar, after I click on a 'done' button, the tabbar controller needs to switch to the first tab and auto refresh the tableview in it.
I am able to execute on the first part
//Switch to the first tab's view
self.tabBarController.selectedViewController
= [self.tabBarController.viewControllers objectAtIndex:0];
However I need some advise on how to refresh the first view's tableview immediately after the switch is made. Any advise is appreciated.
EDIT: Updated requirement
Note: I do not want the view in the tabbar to reload everytime someone clicks on the tab. The reload should only happen in tab 1's tableview when
1) User is in tab 2
2) User clicks on 'Done button' in tab 2
3) App switches to tab 1 + Reloads the tableview in tab 1
Rationale is that the user will update some information in tab 2 which can only be viewed in tab 1. I want the user to be able to view the updated info immediately after switching to tab 1.
You could just do [tableView reloadData] in the first view's viewDidAppear: method?
EDIT: Editing to add additional data.
General caveat here, Apple tends to frown upon having custom UI Patterns like this. I'm not sure what your app is trying to do here, but you should mostly stick with switching tabs only if the user explicitly clicks on that tab. Have you looked at modal view controllers if you want to present a screen and get some data back, instead of having it in a tab bar?
If not, I guess you could have a solution where the first tab is a delegate of the second tab. When the button is clicked, you could call [delegate doneBtnClicked:] so the control shifts to the first tab. In that function, you could use the setSelectedIndex: to your current tab and call reloadData: on the table view.
You can send NSNotification after
pressing done button on second tab
and handle this notification on first tab controller.
So, create a DONE Button as a UIBarButtonItem, and in it's IBAction, do the following.
For reloading the tableView for the view in the first tab, put that tableView as that class' property , and reference the class like #class class1 , and create an object as a property class1 *object1 for View1 (Tab1) in the class for View2 (Tab2), and access the array1 using object1 like
[class1.object1.array1 reloadData];
And for bringing the view to tab one, use
self.tabBarController.selectedIndex = 0;
Thats pretty much it !
Alternatively you can also use a singleton class for this purpose.