Newbie Alert! : ) There are multiple views in my app, all set up in the story board and all having their own subclassed UIView classes with their own overwritten drawRect-methods. One of them works as a button and is able to redraw itself via setneedsdisplay and calls a function of another UIViews class:
import UIKit
class Button: UIView {
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
let touchPoint: CGPoint! = touches.anyObject()?.locationInView(self)
if butouched == true{
if touchPoint.x > bounds.size.width - bounds.size.height && touchPoint.x < bounds.size.width && touchPoint.y > 0 && touchPoint.y < bounds.size.height{
counter++
setNeedsDisplay() //thats the setNeedsDisplay that works
DrawGraph().updateModell()
}
}
}
The problem now is that the setNeedsDisplay in this function didn't work, even though the updateModell-function is called:
import UIKit
class DrawGraph: UIView {
func updateModell() {
setNeedsDisplay() // thats the setNeedsDisplay that doesn't work
}
So I googled and googled but just can't figure out whats wrong. And yes, this is my first week with Swift and iOS...
Create an outlet for between your View on Storyboard and DrawGraph, suppose you name it DrawGraphV, be sure that view is Custom class DrawGraph, you don't need the method updateModell, just call directly DrawGraphV.SetNeedsDisplay