Questions tagged [viewcontroller]

viewcontroller is a design pattern which is a hybrid of the view and controller components of the MVC architecture

A viewcontroller responds to events by dispatching calls to a mapping table which matches views and controllers with each event target. It is implemented as an object in many frameworks, including:

2792 questions
638
votes
28 answers

Presenting modal in iOS 13 fullscreen

In iOS 13 there is a new behaviour for modal view controller when being presented. Now it's not fullscreen by default and when I try to slide down, the app just dismiss the View Controller automatically. How can I prevent this behaviour and get back…
pascalbros
  • 16,122
  • 5
  • 23
  • 35
241
votes
20 answers

How to dismiss ViewController in Swift?

I am trying to dismiss a ViewController in swift by calling dismissViewController in an IBAction @IBAction func cancel(sender: AnyObject) { self.dismissViewControllerAnimated(false, completion: nil) println("cancel") } @IBAction func…
rshankar
  • 3,045
  • 2
  • 18
  • 19
106
votes
16 answers

In iOS, how to drag down to dismiss a modal?

A common way to dismiss a modal is to swipe down - How do we allows the user to drag the modal down, if it's far enough, the modal's dismissed, otherwise it animates back to the original position? For example, we can find this used on the Twitter…
foobar
  • 10,854
  • 18
  • 58
  • 66
99
votes
8 answers

Swift programmatically navigate to another view controller/scene

I'm using following code to programmatically navigate to another ViewController. It works fine, but it some how hides the navigation bar. How do I fix this? (the navigation bar is created by embeding the ViewController in the navigation controller…
Victor
  • 1,603
  • 4
  • 17
  • 24
96
votes
3 answers

iOS Nested View Controllers view inside UIViewController's view?

Is it typically bad programming practice in iOS to have a nested view controller's view inside UIViewController's view? Say for instance I wanted to have some kind of interactive element that responds to user's touches, but only takes up maybe 25%…
Skyler
  • 2,834
  • 5
  • 22
  • 34
95
votes
12 answers

Programmatically switching between tabs within Swift

I need write some code to switch the view to another tab when the iOS app starts (so, for example, the second tab is shown by default rather than the first). I'm new to Swift, and have worked out the following: The code should probably go in the…
Oliver Spencer
  • 2,021
  • 3
  • 16
  • 22
93
votes
16 answers

How to Navigate from one View Controller to another using Swift

I'd like to navigate from one view controller to another. How can I convert the following Objective-C code into Swift? UIViewController *viewController = [[self storyboard]…
sathish
  • 1,180
  • 1
  • 9
  • 9
88
votes
2 answers

How do I create a view controller file after creating a new view controller?

I am developing a tabbed application. When I create a new view controller and link it to the tab bar controller, unlike the other two default view controllers, this one has no viewcontroller.swift file. How can I create this file? I am using Xcode 6…
Kian Cross
  • 1,818
  • 2
  • 21
  • 41
83
votes
14 answers

Swift presentViewController

I programatically have multiple View Controllers in an iOS Swift Project. I do not have the storyboards and would like to avoid them if possible. Is there a way to switch to another viewcontroller.swift file (We will call it view2.swift) and have it…
Z-Tech
  • 4,360
  • 4
  • 17
  • 10
81
votes
5 answers

presenting ViewController with NavigationViewController swift

I have system "NavigationViewController -> MyViewController", and I programmatically want to present MyViewController inside a third view controller. The problem is that I don't have navigation bar in MyViewController after presenting it. Can you…
67
votes
14 answers

Loading ViewController from xib file

I had a MyViewController.swift and a MyViewController.xib presenting the layout of MyViewController. I tried different methods to load this view controller including: //1 let myVC = UINib(nibName: "MyViewController", bundle: …
bluenowhere
  • 2,683
  • 5
  • 24
  • 37
60
votes
7 answers

Xcode - How to connect XIB to ViewController Class

I created first my TestViewController.h and *.m. Afterwards my TestView.xib. Now I need to tell my xib: "Yes, please take the class TestViewController as my File's Owner". I open up my xib, go to the Identity Inspector of its fileOwner and choose…
mogio
  • 843
  • 2
  • 7
  • 18
50
votes
10 answers

Dismiss more than one view controller simultaneously

I'm making a game using SpriteKit. I have 3 viewControllers: selecting level vc, game vc, and win vc. After the game is over, I want to show the win vc, then if I press OK button on the win vc, I want to dismiss the win vc AND the game vc (pop two…
codeinjuice
  • 664
  • 1
  • 5
  • 14
45
votes
9 answers

Swift: Reload a View Controller

I need to refresh a view controller when a certain button is tapped. Simply activating viewDidLoad() does not seem to be working for what I need to do. However, when I leave the view controller then come back to it, it seems to work perfectly? How…
Matt Spoon
  • 2,760
  • 5
  • 25
  • 41
44
votes
5 answers

Only ONE VIEW landscape mode

I finished my iOS app but I need to set only ONE view to landscape mode, the rest of the views can only be seen in portrait mode. I'm using Xcode 5.1 and I created all of my Views by dropping in my storyboard View Controllers from the right panel,…
maeq
  • 1,073
  • 1
  • 12
  • 23
1
2 3
99 100