Questions tagged [viewdidload]

Method in UIViewController class (Apple iOS SDK) for managing the view. Called after the controller’s view is loaded into memory.

This method is called after the view controller has loaded its associated views into memory. This method is called regardless of whether the views were stored in a nib file or created programmatically in the loadView method. This method is most commonly used to perform additional initialization steps on views that are loaded from nib files. Available in iOS 2.0 and later.

722 questions
1
vote
3 answers

When to use init() when creating UIViewController?

In the past I always used viewDidLoad to initialise my ViewControllers, mostly to perform additional initialization on views as it is suggested by Apple's documentation. Sometimes however, I also initialise model objects in the viewDidLoad that help…
Andi
  • 8,154
  • 3
  • 30
  • 34
1
vote
0 answers

Error with TableView and ViewDidLoad

I'm trying to make a table view with sections. So far so good. But when I add the override ViewDidLoad immediately under the structure, I get an error message: Type 'ViewController' does not conform to protocol 'UITableViewDataSource'. If I delete…
1
vote
1 answer

Objective c handle adding child view controller or remove from parent

I have a small question about UIViewController. Is it possible to handle, in a custom UIViewController class, when the controller is added to current view controller using [self addChildViewController:customViewController]; or when removing…
1
vote
0 answers

viewDidLoad errors in connection with view controllers

After upgrading to Swift 3, I started getting a BAD INSTRUCTION error every time I clicked a button that was supposed to open a new view controller, relating to the code that's in my ViewDidLoad. Here's the code in my ViewDidLoad: if teacherModeVar…
TDM
  • 814
  • 2
  • 12
  • 21
1
vote
1 answer

IBAction does not have a sound and animation , swift

I wanted to add sound and animation to button, but, it doesn't work, for example : @IBAction func retry(sender: AnyObject) { buttonBeep?.play() sender.setImage(UIImage(named: "retryTwo.png")!, forState: .Highlighted) …
artG
  • 235
  • 3
  • 12
1
vote
1 answer

If not in viewDidLoad, where should I make initial network calls (say, to initially populate a feed)?

Previously I made my initial network calls to populate the user's feed in viewDidLoad, right after all the views were set up. However, with iOS' state restoration mechanism, this doesn't work as the state restoration is performed after viewDidLoad,…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
1
vote
2 answers

When does a UIView know how big it is?

I have a subclass of UIView that draws a picture onto itself using CAShapeLayers. I want the drawing to adapt to whatever size the UIView is given by AutoLayout. I gave it a drawGraph() function that gets its current size from .bounds.size and then…
Robert
  • 6,660
  • 5
  • 39
  • 62
1
vote
1 answer

Where in view lifecycle to update controller after modal UIViewController dismissed

I have a UIViewController with a UILabel that needs to display either "lbs" or "kg". My app has a settings screen (another UIViewController) that is presented modally over the first view controller and the user can select either of the two units and…
1
vote
2 answers

calling function in viewDidLoad crash

Calling parseString crashes my application. myOptionalString is getting set from didSelectRowAtIndexPath in a tableview. The information is definitely get passed to this view controller. The method also works if called from a button press. But in…
Brian
  • 924
  • 13
  • 22
1
vote
3 answers

Using property accessors on viewDidLoad - Objective C

As far as I know you should always use accessors to access or modify a property, except in two scenarios: init dealloc Don’t Use Accessor Methods in Initializer Methods and dealloc The only places you shouldn’t use accessor methods to set an…
Pablo A.
  • 2,042
  • 1
  • 17
  • 27
1
vote
1 answer

Swift - viewing different position on viewDidLoad and viewDidAppear

I have an understanding problem... I created two similar views (same origin and same size) and section view, While i created those views - one in viewDidLoad and the other in viewDidAppear - when i put similar starting point in the origin x and y of…
r.pul
  • 109
  • 2
  • 9
1
vote
3 answers

Programmatically layout iPhone UIView?

I am using the iPhone toolchain on Linux and so I have no Interface Builder. So how could I layout my view in my ViewController subclass? For example, I want a UITextView in the middle of the screen? Should I do this in the loadView or viewDidLoad.…
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251
1
vote
1 answer

viewDidLoad vs viewWillAppear Where to setup tableview & its datasource?

I have an UIViewController subclass where I have an UITableView. This is the way I use viewDidLoad & viewWillAppear so far. -(void)viewDidLoad { //Setup my datasource //Setup my views, tableviews,…
Confused
  • 3,846
  • 7
  • 45
  • 72
1
vote
3 answers

Add UIScrollView to UIView programmatically not work in viewDidLoad but work in viewDidAppear?

I'm using autolayout. I add a scrollview programmatically to uiview like the code below. I am trying to run initShopView in view did load but it just not work and not add the scrollview to view at all. I have see the view hierarchy capture. class…
Yan Li
  • 1,699
  • 2
  • 16
  • 25
1
vote
5 answers

How to execute certain code when returning to a view swift

When reversing the segue of a view, I would like to have certain code performed. This is unlike viewdidload, or viewdidappear, because I don't want it to run when the app first launches, as it is my initial view controller, but only when returning…
Khoury
  • 411
  • 1
  • 4
  • 21