Reputation: 123
Hi trying to do something very simple in swift, graphically add a view to sit on my maiview story board, with a button that if clicked, it will remove the view from the scene. currently it removes everything and it goes black, subview and super maiView
so i have made another script which uses the tag attribute but it throws a error
@IBAction func removeView(sender: UIButton) {
if view.tag == 99
{
view.removeFromSuperview()
}
}
saying the view is not NSCoding compliant.
the subview viewp does have a controller which inherits from UIView, goal is to make a tool tip to sit on the app when a user uses it to show them how to use it.
Upvotes: 0
Views: 2612
Reputation: 628
@IBAction func removeView(sender: UIButton) {
if view.tag == 99
{
view.dismissWithClickedButtonIndex(0, animated: true)
view.removeFromSuperview()
}
}
Upvotes: 1
Reputation: 958
First You Have To Take Outlets For Both Views.
@IBOutlet weak var currentView1: UIView!
@IBOutlet weak var currentView2: UIView!
var isFirstView:Bool = true {
didSet{
if isFirstview {
currentView1.removeFromSuperview()
} else {
currentView2.removeFromSuperview()
}
}
}
Handle Bool Variable in Button Action
@IBAction func onTapScan(sender: UIButton) {
isFirstView = !isFirstView
//handle here depends on your Condition
}
Upvotes: 1