From the iphone system APP “Contacts”, in the “All Contacts” GUI and click “Add”, it will segue to “New Contact” GUI. Then from the “New Contact” GUI and add “new” item then click “Done”, it will seuge to the contact detail GUI(screenshot image 3). The issue is that: I used “Show(push)” to segue to image 3 from “Done” button,
but the NavagationItem in the left corner displayed as “ back to New Contact “ rather than “back to All Contact”.
I attached the screenshot to describe the issue as bleow:
screenshot
I tried two ways:
way 1: pop the vc which matches the image2. The isssue is that New Record page will jump to image1 first, then jump to image3.
if let nav = self.parentViewController as? UINavigationController {
if let vc0 = nav.childViewControllers.last as? AddRecordTableViewController {
nav.popViewControllerAnimated(true)
}
}
performSegueWithIdentifier(Constants.SegueAddRecordVCToViewRecordVC, sender: nil)
way 2:
used the removeFromParentViewController to discard the vc matches image2. The issue is that the Navagation bar button in the left corner still displayed as “
if let nav = self.parentViewController as? UINavigationController {
if let vc0 = nav.childViewControllers.last as? AddRecordTableViewController {
vc0.removeFromParentViewController()
}
}
performSegueWithIdentifier(Constants.SegueAddRecordVCToViewRecordVC, sender: nil)
Why dont you try using self.dismissViewControllerAnimated(true, completion: {}); when "Done" is pressed.
Related
I am using following layout design
but when i click on central circular button it's cover the whole screen ... i want to make tabbar visible on every click ...
I try to open ViewController as a sub view with following code
guard let StoreVC = self.storyboard?.instantiateViewController(withIdentifier: "StoreVC") else { return }
StoreVC.view.frame = self.view.bounds
self.addChild(StoreVC)
self.view.addSubview(StoreVC.view)
StoreVC.didMove(toParent: self)
but its cover the entire screen including tabbar ..
i try following code but still does't work as expected ...
guard let StoreVC = self.storyboard?.instantiateViewController(withIdentifier: "StoreVC") else { return }
self.definesPresentationContext = true
StoreVC.modalPresentationStyle = .overCurrentContext
self.present(StoreVC,animated: true, completion: nil)
Embedding it in a navigation controller also does't work ...
This circular button is not the part of Tabbar but i want it to act like a tabBarItem ...
if i make it part of tabbar it upper part not click able ...
just like explain in this question TabBarController adding custom button not clickable issue
I have created my own TabView the first tab is always the Home tab which contains a TableView . The other 3 Tabs Search, Menu and Inbox are subviews . I can go from
Home to Search then Back to Home and it works
Home to Menu then Back to Home and it works too
Home to Menu then to Search and back to Home brings me back to the Menu subview . I essentially want to eliminate all subviews when clicking the Home Tab . Also each TabView is in it's own controller .
This is my code
From Home Controller to Menu Controller
#IBAction func MenuTabAction(_ sender: UIButton) {
let Popup = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MenuC") as! MenuC
self.addChildViewController(Popup)
Popup.view.frame = self.view.frame
Popup.view.tag = 100
self.view.addSubview(Popup.view)
Popup.didMove(toParentViewController: self)
}
From Menu Controller to Home Controller & Search Controller
#IBAction func HomeTabAction(_ sender: UIButton) {
if let viewWithTag = self.view.viewWithTag(100) {
print("Tag 100")
viewWithTag.removeFromSuperview()
}
}
#IBAction func SearchTabAction(_ sender: UIButton) {
let Popup = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LocalSearchC") as! LocalSearchC
Popup.view.frame = self.view.frame
Popup.view.tag = 100
self.view.addSubview(Popup.view)
Popup.didMove(toParentViewController: self)
}
I am guessing that the remove superview only removes 1 superview at a time so if I go from Subview1 to subview2 then click on the HomeTab it brings me to subview1 instead of the original HomeTab . Is there a way to remove all superview/subviews when clicking the Home Tab ?
Each Tab got it's own view controller. Ideally, you should removeFromSuperview all controllers you're not showing.
At your code, you only removeFromSuperView at HomeTabAction.
Try to change it:
if let viewWithTag = self.view.viewWithTag(100) {
print("Tag 100")
viewWithTag.removeFromSuperview()
}
to
for v in self.view.subviews {
if v.tag == 100 {
v.removeFromSuperview()
}
}
But please, keep in mind that each time a user press any tabs without returning to home (i.e: tapping many times between Menu and Search), it's look like you are just instantiating many controllers, without removing them.
You should remove other Views every time a new one is instantiated. Would be wise to give a unique tag to each view controller and remove the hidden others after every change, not only when returning to Home. Or at least, check if the view controller with a given type already is instantiated before create a new one.
Actually, you don't need to manually instantiate the viewcontrollers (LocalSearch, Menu). TabViewcontrollers can link a vc with each tab item via a segue. In fact, when you add your tabvc to the project, it will come with 2 viewcontrollers, each connected to an item in the tabview, and that's it, you just need to replace them or adapt them, no need to "load" them.
The only scenario where you'd need to do this, is if your buttons were "dynamic", as in, the content to be loaded changes depending on some other circumstances. As long as clicking "Search" goes to LocalSearchViewController, just link it with a segue on the storyboard.
I using RWRevealViewController in app. I have a slide menu with couple of cells and each cell is pointed to a viewController. Also, each viewController is embedded in navigationController.
My case is that I have a viewController "A" and viewController "B". If I want to go to any of them, I use the slide menu. However, there is a button in viewController "B" that if I tapped on it, it takes me to viewController "A". In this case, if I want to show viewController "A" with navigation bar and bar button item that shows the slide menu, I used this
let vc = self.storyboard?.instantiateViewController(withIdentifier: "A")
self.present(vc!, animated: true, completion: nil)
This solution works fine if it is in they are in Main storyboard. However, if each one of viewControllers in separate storyboard, I have to specify that storyboard of viewController "A". So, I used this solution
let storyboard = UIStoryboard(name: "A", bundle: nil)
let A = storyboard.instantiateViewController(withIdentifier: "navA")
present(A, animated: true, completion: nil)
In here, The main story board have the container view "SWRevealViewController", slide menu viewController, and a storyboard reference to each viewControllers "A" and "B"
Storyboard name of viewController "A" --> A.storyboard
Storyboard id of navigatoinViewController of viewController "A" --> navA
storyboard reference id of viewController "A" is --> navA
So, when I do that, every thing works except that bar button item does not show the slide menu because revealViewController is equal to nil
The action of bar button item
func sideMenus () {
if revealViewController() != nil {
menuBtn.target = revealViewController()
menuBtn.action = #selector(SWRevealViewController.revealToggle(_:))
revealViewController().rearViewRevealWidth = screenSize.width * 0.75
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
How can I fix this?
I am sorry it is to long but excuse me I could not find a shorter way to explain it
Thanks in advance
I have burger button (menu button) in almost all vc and my main screen is tabBarController. Currently I'm getting the side menu when tapping on the Button .On choosing a menu, it shows the desired vc but the bottom tab bar is not there which was there before i select menu item. I want to have the bottom tabbar in entire pages also in pages from the side menu. I.'m using SWRevealViewController for burger menu
How can I acheive this? Please help me.
The code I'm using in didSelectRowAtIndexPath is:
if indexPath.row == 1 {
let destinationVc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
let newFrontVc = UINavigationController.init(rootViewController:destinationVc!)
revealViewController.pushFrontViewController(newFrontVc, animated: true)
}
You have to add tabBarController between navBarVc and frontVc
let navBarVc = UINavigationController()
let tabBarVc = navBarVc.childViewControllers[0] as! tabBarController
tabBarVc.selectedViewController = yourVc
How about that.
I'm using Swift 2 and xcode 7.1.1.
My app is a tabbar + navigationbar based application.
What I'd like to do:
From my first viewcontroller (CollectionVC) I have a collectionview of images(tabbar at bottom and navbar at top). When you select an image, I transition programmatically to a modalviewcontroller (ImageZoomVC) that allows them to zoom on the image (no tabbar or navbar). From the ImageZoomVC I want to transition programmatically to the UserProfileVC. The UserProfileVC should have the tabbar and navbar like the first view. The navbars back button should also take us back to the ImageZoomVC.
This workflow is similar to facebook. When you select an image, you go to a black screen with just that image and some more info. You can click on anyone tagged in the image and it will push their profile onscreen with the tabbar and navbar back in place.
The Problem:
Once in the ImageZoomVC, I can't transition to the UserProfileVC without losing the tabbar and navbar. I've been able to add a navbar programmatically but there is no back button, and setting a back button hasn't worked. Also, there is no tabbar.
Code:
From my CollectionVC, I transition to the ImageZoomVC from my collectioncell like this:
#IBAction func PhotoButtonPressed(sender: UIButton) {
let imageZoom = ImageZoomVC()
imageZoom.showFrom(self.parentView!)
}
Here is the showFrom function that presents the ImageZoomVC modally. This code is inside the ImageZoomVC:
public func showFrom(viewController: UIViewController) {
//Some stuff here, edited for length
viewController.presentViewController(self, animated: false) {
UIView.animateWithDuration(ImageZoomVC.TransitionAnimationDuration,
delay: 0,
options: [.BeginFromCurrentState, .CurveEaseInOut],
animations: {
[weak self] in
self?.collectionView.alpha = 1
self?.collectionView.transform = CGAffineTransformIdentity
},
completion: {
[weak self] finished in
self?.view.userInteractionEnabled = finished
}
)
}
}
This is the code I'm attempting to use to transition to the UserProfileVC with navbar and tabbar. This doesn't work. It will present the VC, but there is no tabbar or back button.
func userSelected (sender: UIButton) {
let vc = self.presentingViewController?.storyboard?.instantiateViewControllerWithIdentifier("User Profile") as! UserProfileVC
let newNav = UINavigationController(rootViewController: vc)
newNav.navigationBar.barTintColor = UIColor().specialPurple()
newNav.navigationBar.translucent = false
self.presentViewController(newNav, animated: true, completion: nil)
}
A couple notes: The ImageZoomVC doesn't exist in storyboard. It is called and instantiated programmatically.
The ImageZoomVC is based off Agrume from Github found here:
https://github.com/JanGorman/Agrume
I'd like to push the UserProfileVC like facebook does. This current code presents it from the bottom. The code pushViewController is not recognized here in xCode.
Let me know what you think. All thoughts are welcome. Thanks.