3

I can not update my custom view when you turn the screen of my device.

I tried to do this:

override func viewDidLoad() {
        super.viewDidLoad()


       var myCustomView = Customview()

       self.view.addsubview(myCustomView)
        }
    }

    override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {

        // Reload Data here

        self.view.reloadData() // Incorrect

    }

But get me error:

the method "UIView" does not have a method called reloadData

Paul
  • 43
  • 1
  • 8

3 Answers3

3

You want to call reloadData() on the instance of your UITableView (assuming there is any). UIView does not provide such a method.

Edit to get notified when the screen orientation has changed, set up a notification:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "didRotate:", name: UIDeviceOrientationDidChangeNotification, object: nil)

and implement the selector, e.g.

func didRotate(notification: NSNotification)
{
    myTableView.reloadData()
}
Sebastian
  • 8,046
  • 2
  • 34
  • 58
3
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {

    // Reload Data here

    self.view.reloadData() // Incorrect

}

UIView is not a UITableView it doesn't have reloadData method out of the box.

You can implement this method manually -> have fun :)

Coldsteel48
  • 3,482
  • 4
  • 26
  • 43
1

I think it's work for you

objective-C

[self.view setNeedsDisplay];

swift

self.view.setNeedsDisplay()

override func viewDidLoad() {
    super.viewDidLoad()
    
    
    var myCustomView = Customview()
    
    self.view.addsubview(myCustomView)
}

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
    
    // Reload Data here
    
    self.view.setNeedsDisplay()
    
}
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
  • No this is not working. When I turn my device layout is not regenerated and you see evil – Paul Jan 21 '15 at 08:48