How can refresh UIView in UITabBarController? - uitabbarcontroller

I'm stack on refreshing view in TabBar. The UIView is read only first time I pressed the TabButton and does not "viewDidLoad" next time. I want to refresh UITableView every time I pressed the button.
Thank you!

Ok Found a solution (just right after i posted this here)
add:
- (void)viewWillAppear:(BOOL)animated
{
NSLog(#"View appears");
}
to your ViewController and you will see that this method will be called, by clicking the TabButton ;)

Related

SwiftUI delete Navigation Stack

When starting my app for the first time, a little setup is required. After this setup, the user should then come to the MainView.
Now I want it to be so that the user cannot jump back to the last setup step as soon as he reaches the MainView.
All the solutions I can find is to simply remove the back button. But this is not enough for me, I'm currently working with tvOS, there is a back Button on his remote. If he then presses this, he should ideally just come back to the tvOS home screen.
Is there any possibility to delete the complete navigation stack or something similar with the same result?
You can replace your entire view hierarchy at the parent level (above your NavigationView if a given condition is true:
var body : some View {
if setup {
//parent component of views for once setup is done
MainView()
} else {
//parent component of the setup views (including a NavigationView)
SetupScreens()
}
}
So, on the final setup screen, set setup to true (this should probably be stored in an ObservableObject that each view can access [possible via an .environmentObject]) and the NavigationView will be destroyed and the hierarchy will be replaced with MainView.

UIButton not getting focus

I have my code in Swift 3. I have two UITextFields and a UIButton in my view. I have the textFieldShouldEndEditing delegate of the first UITextField which is fired when I focus on the 2nd UITextField. However when I tap on the UIButton this delegate is not fired. I had thought that when a UIButton gets focus then the UITextField’s event will automatically fire since it is losing focus. However, when I tap on the UIButton, the cursor is still blinking in the UITextField, which means it is not losing focus.
Any ideas on why the UIButton is not getting focus will be most appreciated.
Thanks.
This is an infuriating aspect of developing forms on iOS. Button taps don't remove focus from UITextField / UITextView the same way they would in an HTML form.
I'm sure there are more elegant ways to solve this, but if I want to consistently do this across all forms I ensure that the following line of code is run when users tap on any buttons of mine.
- (void)userDidTapButton:(id)sender
{
[[[UITextField new] becomeFirstResponder] resignFirstResponder]
// the above embarrassing line of code basically creates a new textfield
// puts focus in it (thereby removing focus from any existing textfields
// and then removes focus again
// this ensures that delegate events fire on your existing textfields
// finally, run any other button code
}

How to trigger the button action when the keyboard is still on screen in swift?

I have a problem and I can't find the solution for it. At the moment I have a tap gesture recogniser in my VC's viewDidLoad() that will dismiss the keyboard if a tap is recorder on screen. Problem is that when the user has finished completing the text fields and he presses the "Register Account" button it is still recognised as a tap and only removes the keyboard but the button does not respond to the tap and the selector function is not called.
I want as soon as the button was tapped with the keyboard on screen to call the function and do its business. Please help.
Just posting the first line of the function called by the button because for this question is as far as I have got:
#objc fileprivate func createAccount() {
confirmPasswordTextField.resignFirstResponder()
If you just want to make all buttons actionable (along with the keyboard dismissing) all you have to do is make your tap gesture recognizer not cancel touches in view:
var cancelsTouchesInView: Bool { get set }
So just set:
myTapGesture.cancelsTouchesInView = false
https://developer.apple.com/documentation/uikit/uigesturerecognizer/1624218-cancelstouchesinview
This will make it so that when the user taps on the "Register Account" button the keyboard will dismiss and the action will also be performed.

Repositioning Master View display button in Split View Controller

As you know, split view controller hides the master view and displays detail view in full screen mode in ipad. In the full screen mode, ios creates a bar button for the master view on the navigation bar. My question is, is it possible to reposition that button to the far right instead of left? Because my detail view is embedded inside a navigation view controller and there are severals views associated with it. It gets confusing when master view is hidden and the detail view has button to go back to the previous view.
In above screencap, "Category" is a button to display the masterview and "List of Events" is a back button. If you have better way to handle this situation, please feel free to suggest.
Yes, you can do it just send a NotificationCenter.default to the split view controller and change self.preferredDisplayMode in your splitview and coming to moving the category buttom u either can use the right bar button in navigationbar or create your custom navigation bar.
Hope this helps
For those who are having the same issue, I found a very simple solution. All you need to do is assign the rightBarButtonItems with leftBarButtonItems value and set the leftBarButtonItems to nil. Voila, that's about it.
if let leftButton = self.navigationItem.leftBarButtonItems {
self.navigationItem.rightBarButtonItems = leftButton
self.navigationItem.leftBarButtonItems = nil
}

Navigation bar and Tab bar disappears when doing push segue

I have the following structure in InterfaceBuilder in XCode:
Tab bar controller
Navigation bar controller
View Controller A
.. push segue to..
View Controller B
However I cannot get the push segue to keep the nav bar and tab bar. It also animates from the bottom like a modal segue.
This is how I start the segue:
self.performSegueWithIdentifier(DETAIL_MEETING_SEGUE_ID, sender: self)
Both VC1 and VC2 have unchecked "Hide Bottom Bar on Push".
In Interface Builder tab bar and nav bar are showing correctly. Also, when dragging a segue directly from a button to VC 2 with push set it works perfectly.
Any ideas?
I experienced a similar issue after embedding tab bar stacks of VCs into navigation controllers. There was a storyboard push segue from VC a to VC b (in a different stack) that was called using performSegue:.
My fix:
Delete the segue in storyboard, then create it again the exact same way. After this the VC b showed the tab bar and the navigation bar as expected.
Filed a bug with Apple Bug Reporter.
I "solved" it by dragging a manual segue from the tableview cell to "View Controller 2". I then gave it the same name as before and made setup in prepareForSegue: as normal. I had to drag multiple segues but it was ok to use the same id for them.
If anyone have a better solution please write it here.