Questions tagged [uiviewcontroller]

The UIViewController class manages the views in iOS apps and mediates the interaction between an app's views, its underlying model objects, and the overall workflow.

The UIViewController class manages the views in iOS and watch-os apps and mediates the interaction between an app's views, its underlying model objects, and the overall workflow.

View controllers are the foundation of your app’s internal structure. Every app has at least one view controller, and most apps have several. Each view controller manages a portion of your app’s user interface as well as the interactions between that interface and the underlying data. View controllers also facilitate transitions between different parts of your user interface.

To quote from the Overview of the UIViewController Class Reference:

The UIViewController class provides the fundamental view-management model for all iOS apps. You rarely instantiate UIViewController objects directly. Instead, you instantiate subclasses of the UIViewController class based on the specific task each subclass performs. A view controller manages a set of views that make up a portion of your app’s user interface. As part of the controller layer of your app, a view controller coordinates its efforts with model objects and other controller objects—including other view controllers—so your app presents a single coherent user interface.

References:

16290 questions
44
votes
11 answers

How can I switch views programmatically in a view controller? (Xcode, iPhone)

Have been struggling with this for a while, and can never seem to get a direct answer. Any help is appreciated!
mishajw126
  • 517
  • 1
  • 5
  • 14
43
votes
2 answers

Use of background/foreground methods in AppDelegate

I'm planning to implement multi-task in my app. I can see many methods here to do that in the AppDelegate like applicationWillResignActive, applicationDidEnterBackground, applicationWillEnterForeground, ... But.... I don't see the way they should be…
Oliver
  • 23,072
  • 33
  • 138
  • 230
43
votes
11 answers

How to present a ViewController on Half screen

I have a UIViewController which have only a UIView which covers 1/3 of the viewController from bottom. Like this I want to present this viewController on an other ViewController. It should appear from bottom animated and it should dismiss to the…
Umair Afzal
  • 4,947
  • 5
  • 25
  • 50
43
votes
5 answers

Initializer does not override a designated initializer from its superclass

So I've just upgraded to Xcode 6.3 Beta 3 and a lot of error(s) are appearing relating to the following: Initializer does not override a designated initializer from its superclass. override init() { super.init() } For example this is a…
gotnull
  • 26,454
  • 22
  • 137
  • 203
42
votes
11 answers

How to get the previous viewcontroller that pushed my current view

The home page of my app has UIButtons, btnIncome and btnExpense. Pressing on this buttons pushes IncomeVC and ExpenseVC respectevely,which are two UIViewControllers with UITabBar added via xib. The tabBar have 4 items. Selecting on each tab item…
42
votes
3 answers

How do I give an "identifier" to a view controller within my storyboard?

The instantiateViewControllerWithIdentifier: method requires that the view controller I pass have an identifier. I went to my storyboard and clicked on my view controller, but I see no option to set the identifier. Where exactly do I find this…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
40
votes
6 answers

Custom smaller Detents in UISheetPresentationController?

Apple has finally released an Apple Maps-style "bottom sheet" control in iOS 15 in 2021: UISheetPresentationController. This type of sheet natively supports "detents", the heights at which a sheet naturally rests. The default large() detent…
pkamb
  • 33,281
  • 23
  • 160
  • 191
40
votes
12 answers

Unable to hide the navigationBar when embedding SwiftUI in UIKit

I am trying to hide the navigationBar when putting some SwiftUI inside of a UIKit UIViewController: override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.navigationController?.setNavigationBarHidden(true,…
Mike Perhats
  • 533
  • 1
  • 7
  • 11
40
votes
12 answers

PageViewController current page index in Swift

I want to get current index of a pageViewController, I don't know how I get the visible pages index. func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool,previousViewControllers:…
LeNI
  • 1,184
  • 2
  • 10
  • 19
40
votes
4 answers

Is the weakSelf/strongSelf dance really necessary when referencing self inside a non-retained completion called from a UIViewController?

Say I have the following method inside a UIViewController subclass: - (void)makeAsyncNetworkCall { [self.networkService performAsyncNetworkCallWithCompletion:^{ dispatch_async(dispatch_get_main_queue(), ^{ …
40
votes
3 answers

Add toolbar to UITableViewController

What is the simplest way to add UIToolBar to UITableViewController? I'm depending on edit functionality, so I can't change UITableViewController to UIViewController easily.
39
votes
3 answers

UIViewController returns invalid frame?

When I start my ViewController in landscape mode (After viewDidLoad is called), I print the frame it's giving me the frame size for portrait mode instead. Is this a bug any suggestions? - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"%@",…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
38
votes
6 answers

Switching ViewControllers with UISegmentedControl in iOS5

I am trying something very simple but somehow I can't get it to work. All I try to do is switching between 2 View Controllers using an UISegmentedControl as you can see it for example in the App Store application in the Highlights tab. I am using…
MrBr
  • 1,884
  • 2
  • 24
  • 38
38
votes
6 answers

UILabel updating stops during scrolling UIScrollView

I have a scrollView with an imageView inside of it. The scrollView is a subView of the superView, and the imageView is a subView of the scrollView. I also have a label (at the super-view level) that receives updated values on its text property from…
brainondev
  • 1,117
  • 1
  • 11
  • 20
38
votes
2 answers

Whats the programmatic opposite of showViewController:sender:

I'm writing an iOS 8 only app and I'm using the new adaptive presentations using a combination of the "Show" and the "Show Detail" segue and the showViewController:sender: and showDetailViewController:sender: methods. My question is what is the…
jackslash
  • 8,550
  • 45
  • 56