I have a function related to the user interface, such as a warning popup, displaying an activity indicator in the middle of the screen, or displaying animation on the screen using a special message.
I want to use then in several viewControllers (VC1, and VC2 in this case), so I do not repeat myself.
Initially, I have the following code that works with both VCs inherited from BaseVC that takes care of these functions.
VC1 is a UIViewController with a built-in TablelView, VC2 is a UIViewController with a built-in collection element.
class VC1: BaseVC {
func viewDidAppear(animated: Bool) {
activityIndicatorBegin()
}
func btnPressed() {
activityIndicatorEnd()
}
}
class VC2: BaseVC {
func viewDidAppear(animated: Bool) {
activityIndicatorBegin()
}
func btnPressed() {
activityIndicatorEnd()
}
}
class BaseVC: UIViewController {
var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
var isCustomViewOnScreen = false
func activityIndicatorBegin() {
if activityIndicator.isAnimating() == false {
activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0,0,20,20))
activityIndicator.center = view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
activityIndicator.color = UIColor.blackColor()
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
}
}
func activityIndicatorEnd() {
if activityIndicator.isAnimating() == true {
activityIndicator.stopAnimating()
activityIndicator.removeFromSuperview()
}
}
func animateACustomViewOnScreen() {
if isCustomViewOnScreen == false {
}
}
func removeCustomView() {
if isCustomViewOnScreen == true {
}
}
}
VC1 UITableViewController VC2 UICollectionViewController.
, BaseVC, UIViewController. , VC ?