Some background at first: I'm developing storyboard based application (ios7) where UITabbarController is the root controller. One of the tabs contain navigation controller. Viewcontroller embedded to that navigationcontroller has button, which opens new viewcontroller when pressed. I'm using push segue to do that.
My issue is following: Every time I press the button and new viewcontroller opens, awakefromnib is always called. I'm trying to do some initializing in the awakefromnib function, but now it is not possible because the function is called always when the viewcontroller appears.
Any help with this?
Related
In my app I have a UINavigationController that puts a navigation bar on all of my ViewControllers and in every ViewController I have a custom back button. In one specific ViewController I need to send some data when going back to the previous ViewController. I was able to do this when the user presses the back button with a custom function, but this function is ignored when user swipes to go back.
I tried using this answer: Adding an action to back swipes swift 4 but calling visibleViewController or topViewController in the navigation controller only gets the view controller that we're going to (the previous ViewController, not the current one). I need the function inside the ViewController we're in before the user swipes back.
How can I call on the back function I made inside my current ViewController to send the data from that ViewController to the ViewController we'll pop to.
Seems like you just need to use viewWillDisappear(_:) and just put the function you made here.
I am new in iOS development and in Swift. I have a question. I added in one of the ViewController NavigationController. But I have some problems with back button cause it doesn't appear on other Views. I tried with self.pushViewController() and with self.present() but it doesn't work. If I mark in NavigationController Is Initial View Controller then everything is fine but I don't want it because then app starts with this screen(where I have NavigationController).
Please help me, what I should to add or to write?
This is an image of my storyboard
And this is what I have if I run and go to another ViewController, as you can see I don't have navigation bar and back button.
You got 2 options :
1) Add a navigation controller in the root ViewController, Hide throughout except the last one. Make sure you push the last VC so Back option will be there by default
self.navigationController.pushToViewController(BarCodeViewController)
2) Use a custom View on top of last viewController add a custom button to that view. But this time present it from previous ViewController
self.present(BarCodeViewController)
when back button clicked dismiss it by adding target to the button. self.dismiss()
For my iOS application, I have a login screen and a register screen, each with their own UIViewController (LoginController and RegisterController respectively). On the register screen, I have added a back button that performs a segue to the login screen.
When I click the back button, the implementation file seems to change (from RegisterController.m to LoginController.m), but the actual screen does not change. I have added the code NSLog(#"In LoginController"); at the top of my LoginController.m file (after [super viewDidLoad];), and when I click the back button on the register screen, my log prints "In LoginController" every time I click the back button, but the screen never changes.
I created the segue similarly to other segues in my application that work correctly. I used the storyboard, held control on the button and dragged the segue to the LoginController.
Does anyone know why this is happening?
EDIT: So I have changed my segues to unwind segues, so that I can get back to the original view of the navigation controller. I have an unwind segue from LoginController to TutorialController, but when I try to unwind from RegisterController to LoginController, the view does not change (but the unwind method in LoginController is called).
So I figured out the problem.
In performSegueWithIdentifier, I had sender:self instead of sender:self.backBtn
I am making a TabBarController application using the template provided by Xcode and I need to reload the second view controller everytime it is clicked. How do I do this ?
Thanks
Whenever the tab bar switches the view controllers, the viewcontroller viewWillAppear function will be called
So add the code in the viewWillAppear function of the UIViewController
I'm new to iphone programming and i'm trying to build an application that has a uinavigationcontroller and the rootviewcontroller is a uiviewcontroller that is basicly a login screen from the login screen the user moves to uitabbarcontroller that has 5 tabs and each tab is a uinavigationcontroller and each navigationcontroller has two button in the navbar one button brings a messages view and the other notifications view each view is a uiviewcontroller.
Now the user can press the message button on every tab and the message view will appear and i want to make sure that if he presses the button on the first tab and then goes to another tab then the message view will disappear and deallocated from memory and when he presses the message button on the new tab then another message view will appear.
I tried the create a single message view in the app delegate and every time that the user presses the message button to call a method from app delegate then in the method i check which tab is pressed and push the view to the navigation controller that belongs to that tab but that doesn't work properly.
You can embed your login views inside the AppDelegate and show them as needed. From there you would load your rootController, which should be your tabBar. Then you can load up your navigation controller inside each tab. One for each tab. Your message view can be called from any of the tabs. Just need to make sure you layer your controllers the right way.
AppDel --> TabBar --> NavController --> Individual Views
Do you realize that you can replace the root view controller in a window? Your app delegate's -applicationDidFinishLaunching:withOptions: method probably does something like:
window.rootViewController = loginViewController;
When you set the window's rootViewController property, the window will add that view controller's view as a subview of itself.
There's nothing particularly special about -applicationDidFinishLaunching:withOptions: -- it just happens to be the delegate method that's called when the app has finished loading and is ready to get down to business. You can set the window's rootViewController property just as well from other methods, so when your login view controller determines that the user has successfully logged in, it can do something like one of the following:
instantiate the tab bar controller and set the window's rootViewController property itself
send a message to its delegate (which would probably be the same object as the app delegate) to inform it that login was successful; the delegate could then install the tab bar controller
broadcast a notification to tell anyone who cares that login was successful, and let someone else install the tab bar controller