I'm designing an app for IOs in Swift 4.
Firs a login view appears and if you press the login button the following code will be executed:
let storyBoard : UIStoryboard = UIStoryboard(name: "TabBar", bundle:nil)
let resultViewController = storyBoard.instantiateViewController(withIdentifier: "TabBar") as! UITabBarController
resultViewController.modalTransitionStyle = .partialCurl
self.present(resultViewController, animated:true, completion:nil)
If we go to the any view, for example
you will see a table view with 3 sections, the content is static. When you press whenever (doesn't mind if its the cell to the tittle of the section) it goes back to the login page. This happens in all the pages linked at the TabBar when you Tapped the 2/3 first area (the 2 first sections more or less) of the screen.
It seems that it's executing:
dismiss(animated: true, completion: nil)
Why it is having that behaviour? How I can solve it?
This either seems to be a bug or expected behavior. Users have reported it from back in iOS 7.
It seem to me that apple has defaulted the animation to just view the content not interact with them.
Here is an answer discussing the same.
I would suggest you to make a custom logic.
Related
I'm working on a Swift 4 Cocoa Mac OS X (not iOS) project with XCode 9. I have two NSWindows in my main storyboard with different (subclasses of) NSViews. Currently only one window holds the storyboard entry point and so the other one does not appear when the application begins, and I want both windows to appear when the application is loaded.
I've tried googiling with different keywords but so far couldn't find a way. The only method I found was to connect a segue from a button or menu in one window to the other window, so that the other window appear whenever the button is pressed. Is there any of making both windows appear in the beginning the 'right way' (preferablly using functionalities of XCode storyboard)?
You have to get a reference to the window controller in your storyboard from the second window you want to show. Add this code to your NSApplicationDelegate in applicationDidFinishLaunching. Don't forget to set the identifier from the WindowController in the Storyboard
let storyboard = NSStoryboard(name: "Main", bundle: nil)
let windowController = storyboard.instantiateController(withIdentifier: "MyWindowController") as! NSWindowController
windowController.showWindow(self)
Having a bug when i try to delete viewcontroller2 which is connected to vc1. Part of the view in viewcontroller1 seems to disappear even though i remove all connections. Ran in to this problem before on same project when connections were not right.
The first image is how it is supposed to be with listname and a button in lower corner.
The last image is how the tableview looks like when i try to remove the other vc.
Any idea of how to solve this?
I don't know if this is what you want but try putting this in the function for when vc2 closes:
self.navigationController?.popViewController(animated: false)
dismiss(animated: false, completion: nil)
self.view.removeFromSuperview()
self.view = nil
If you provide some code it will be easier to understand.
so I have a basic game going in Xcode. I started with Xcode's basic game template and built my game mostly inside the 'GameScene.swift'. When I finished with my game I wanted to add a start screen with a play button so I made a new UIViewController and added a button. I control click and dragged the button to the GameViewController and created a Modal Segue. I then wanted the game to go back when the player died. I tried various ways to dismiss the view but none worked. I am new to swift and really need help. Let me know what code/info is needed to find a solution. I have tried everything I have found on the internet. I thought I found a way around it by adding a button and Segue to the GameViewController to the menu but after multiple pushed it clogged the system and slowed to a crawl because none were dismissed. I can provide any code needed.
Inside of GameViewController.swift in the GameViewController class I tried making a function that was called when the game ended.
I tried to both pop and dismiss the view controller. The function was called and a line printed to console but the view remained. The only thing printed to console is 'nil'
class GameViewController: UIViewController {
func end(){
print(navigationController?.viewControllers as Any)
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
}
# Vollan heres the pic
Here is the screenshot of the storyboard.
thanks in advance.
If you pushed the viewController you use self.navigationController?.popViewController(animated: true)
If you presented it modally you use
self.dismiss(self, animated: true)
When its presented from a modal segue you use
self.presentingViewController?.dismiss(animated: true, completion: nil)
I have a modal segue in a storyboard from one view controller to the other. Then I have a button that's connected to an IBAction that just runs
dismiss(animated: true, completion: nil)
Check and redo the connections from the storyboard to the code. Xcode sometimes just looses a connection when making a lot of changes to the code.
I am working on a macOS app that presents a list of customer master records in a table view. Double-clicking a row in the table view should open a new window where the user can view and edit the customer information.
This is an Xcode 8.3.3 project using a storyboard and Swift.
It is not a document or core data app.
I have the main window working up to the point where the table view is displaying the records correctly and the associated view controller is receiving the double-click events and logging them to the console.
I have created an additional window controller and view for the edit window and verified its basic functionality by temporarily marking it as the initial controller.
What I haven't been able to figure out is how to display a new instance of that window when the user double-clicks a row.
Thanks to #Joshua Nozzi I'm closer. Here is the code at this point.
let storyboard = NSStoryboard(name: "Main", bundle: nil)
if let windowController = storyboard.instantiateController(withIdentifier: "xyzzy") as? NSWindowController
{
windowController.showWindow(self)
}
It's generating a
(Storyboard: 0x620000000680) doesn't contain a controller with
identifier 'xyzzy'
error.
The Window Programming Guide is a great place to understand how windows are managed in general.
Specifically (assuming you know how to present a window controller scene in storyboards), you need somewhere to store references to the new window controllers so they’re not immediately deallocated (and disappear) when presented.
In your case, you may want to keep an array of your open detail windows in the master window controller, so that if the master goes away, the details do as well. When a detail window is open (a controller instance is created and its window shown), you’ll store its controller in the array; when closed, you remove its controller from the array so it’s deallocated.
There are a number of ways to do this, depending on how much control you want, how you want child window ownership to work, etc., but this basic pattern is usually sufficient.
To instantiate a new window controller scene from a storyboard:
var myWindowController = NSStoryboard(name: "MyStoryboardFileName", bundle: nil)?.instantiateControllerWithIdentifier("MyWindowControllerIdentifier") as MyWindowControllerClass
myWindowController?.showWindow(self)
Additionally, to open new window, this code can help you
windowController.contentViewController = tabViewController
The full code is like that i used it in my project:
#objc func openApplicationView(_ sender: Any?) {
let mainStoryBoard = NSStoryboard(name: "Main", bundle: nil)
let tabViewController = mainStoryBoard.instantiateController(withIdentifier: "tabView") as? TabViewController
let windowController = mainStoryBoard.instantiateController(withIdentifier: "secondWindow") as! TabViewWindowController
windowController.showWindow(self)
windowController.contentViewController = tabViewController
}
It can helpful if you've closed the mainWindow. So you need to add one windowController and tabViewController(you can use normal view controller) in your own underlying storyboard.
In my side the tabViewController has been extended by NSTabViewController and tab view component has been bound with this class.
Note: I've also added the windowController in my Main.storyboard as a component and identified to use then on coding side.
***** You can download this project to see the issue *****
I've embedded SLPagingViewSwift in my project.
In the third VC i added a button (and a table):
The button configured to do a segue (Present Modally):
In the target VC i have a button (marked in square green above) that do:
#IBAction func dissmissIt(_ sender: AnyObject) {
dismiss(animated: true, completion: nil)
}
But after the target VC is dismissed i see the button in the third VC in a different location (higher):
The layout is configured, button 40 pixels from the top (and table 8 pixels from the button):
What went wrong?
I guess the initial layout configuration takes the SLPagingViewSwift navigation bar into consideration but after the dismiss it recalculates the layout from the top of the screen.
What is the right way to perform the segue and dismiss the target VC while keeping the layout as designed?
I saw this answer
But i was not sure where to use it. i tried:
nav?.view.translatesAutoresizingMaskIntoConstraints = false
and
controller.view.translatesAutoresizingMaskIntoConstraints = false
But with no luck.
***** You can download this project to see the issue *****
Thanks.
I had the same problem. After a lot of hour trying to fix it, I found the solution.
Click on your segue
On the right panel click on 'Show the attributes inspector'
Set the Presentation option to 'Over Full Screen'.
Worked for me. I hope it works for you!