Orkhan Alizade
Orkhan Alizade

Reputation: 7549

how to make my variable visible from

I created inside of viewDidLoad the next view:

var myView = UIView(frame: CGRectMake((width-50)/2, (height-50)/2, 50, 50))

and set to it:

myView.alpha = 0

But I want to make it myView.alpha = 1 when user tapped on tableView cell. But it does not visible from

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { ... }

How can I do it visible from there? Do not offer to create it, view, in XCode visually.

It prints the next error:

'ViewController' does not have a member named 'myView'

enter image description here

Upvotes: 1

Views: 77

Answers (2)

Ashish Kakkad
Ashish Kakkad

Reputation: 23882

Define the variable under your @IBOutlets

var myView:UIView!
var width:CGFloat!
var height:CGFloat!

And in your viewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()

    width = mytableview.frame.size.width
    height = mytableview.frame.size.height
    myView = UIView(frame: CGRectMake((width-50)/2, (height-50)/2, 50, 50))
    self.view.addSubview(myView)
}

Upvotes: 2

sriram hegde
sriram hegde

Reputation: 2471

you need to add the created view into the main View

var myView = UIView(frame: CGRectMake((width-50)/2, (height-50)/2, 50, 50))
self.view.addSubview(myView)

Upvotes: 0

Related Questions