1

quick question! Sorry for noobiness in advance. I recentely started developing iOS applications and wanted to load a view for clicking a button. Im working in swift4.

 @IBAction func btnAddItem_AddDrinks_Click(_ sender: Any) {
        //[self dismissViewControllerAnimated:YES completion:nil];
        //[self.navigationController popViewControllerAnimated:YES];
        if strIsSpecial == nil {
            ValidationString.sharedManager().showAlert(withTitle: "", messageBody: "Please select either Regular, Special or Free")
        }
        else if ValidationString.sharedManager().isNullString(txtfldOunce.text!) == true {
          //  ValidationString.sharedManager().showAlert(withTitle: ALERT_TITLE, messageBody: "Ounce" + (ALERT_FIELD_SHOULD_NOT_BLANK))

            let alert = UIAlertController(title: "Alert", message: "Ounces shouldn't be left blank", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
        else if ValidationString.sharedManager().isNullString(txtfldUserReference_AddDrinks.text!) == true {

            let alert = UIAlertController(title: "Alert", message: "Drink Name shouldn't be left blank", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)

            //ValidationString.sharedManager().showAlert(withTitle: ALERT_TITLE, messageBody: "Drink Name" + (ALERT_FIELD_SHOULD_NOT_BLANK))
        }
        else {
            if view_Loading != nil {
                view_Loading?.removeFromSuperview()
                view_Loading = nil
                obj_LoadView = nil
            }
            obj_LoadView = LoadView(frame: <#CGRect#>)
            view_Loading = obj_LoadView?.showActivity("Loading....")
            view.addSubview(view_Loading!)
            view.isUserInteractionEnabled = false

The current error is "Editor is placeholder" for obj_LoadView = LoadView(frame: <#CGRect#>). I know I need to put something for CGRect, but unsure what. Any help is appreciated, thanks!

restores
  • 41
  • 3
  • 1
    As you just *started developing iOS applications* please conform to the naming guidelines. Unlike PHP and JavaScript variable names in Swift/Objective-C are supposed to be *camelCased* rather than *snake_cased*. You need to pass a suitable `CGRect`. The simplest value is `.zero` but you might have to specify a non-zero `width` and `height`. – vadian Nov 04 '17 at 19:49

2 Answers2

2

When you start typing, Xcode will autocomplete statements for you. If you don't change the auto-completed arguments, you will get that error.

The problem is this line here:

obj_LoadView = LoadView(frame: <#CGRect#>)

<#CGRect#> needs to get changed with an actual CGRect instead of the placeholder.

Make a CGRect the size you want the new view:

obj_LoadView = LoadView(frame: CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400))

That would make the view's frame 400x400 points.

If you want to make the view the full size of the view its in, you can do this:

obj_LoadView = LoadView(frame: view.frame)
Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58
  • You're welcome. Note that here on Stackoverflow, if someone answers your question, you are supposed to accept it (hit the green check button). I looked at your profile and you haven't accepted any answers. People are less likely to answer your questions if you don't accept any of them... – Jeshua Lacock Nov 05 '17 at 05:10
2

I personally like to create my own activityIndicatorView

class LoadingView: UIView {
    
    private var activityIndicatorView: UIActivityIndicatorView {
        
        let view = UIActivityIndicatorView(activityIndicatorStyle: .white)
        view.startAnimating()
        
        view.center = self.center
        return view
    }
    
    private var isPresenting: Bool = false
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .black
        self.alpha = 0.0
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func present() {
        guard let window = UIApplication.shared.keyWindow else { return }
        window.addSubview(self)
        fadeIn()
    }
    
    func dismiss() {
        guard isPresenting == true else { return }
        fadeOut()
    }
    
    private func fadeIn() {
        UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
            self.alpha = 0.5
        }) { (bool: Bool) in
            self.addSubview(self.activityIndicatorView)
            self.isPresenting = true
        }
    }
    
    private func fadeOut() {
        UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
            self.alpha = 0.0
        }) { (bool: Bool) in
            self.removeFromSuperview()
            self.isPresenting = false
        }
    }
}
Putra
  • 399
  • 9
  • 23