I´m stuck on how to display a view from inside a completion block. If I use the same code outside the completion block the view is shown. I´m sure the block is getting executed and I also have setNeedsDisplay
in a didSet
for an array I use inside the block. So what am I missing?
private var storeViews = [UIView](){ didSet{self.view.setNeedsDisplay()}}
hrd.requestData(from: "somepage.php"){[weak self] (status:Bool,items:[[String:String]]?) in
if status
{
for var i in (0..<items!.count)
{
if let item = items?[i]
{
var shape = CGRect()
shape.size = CGSize(width: 50,height: 30)
let xPosStr = item["xPosition"]
let yPosStr = item["yPosition"]
let position = CGPoint(x: (self?.stringToFloat(xPosStr!))!,y: (self?.stringToFloat(yPosStr!))!)
shape.origin = position
let someView = UIView()
someView.frame = shape
someView.backgroundColor = UIColor.red
self?.view.addSubview(someView)
self?.someViews.append(someView)
}
}
}
}