0

Main screen

I'm trying to work on a code that when the user touches the "ADD TO CART" button, the information currently displayed will be shown on an alert message when the user touches the "VIEW ORDERS" button. I've tried the answer from this question (How to save local data in a Swift app?), but I've found that it doesn't work for me and I've been stuck ever since.

"VIEW ORDERS" button's alert screen (left side). Alert screen after adding another item to cart (right side)

edit: Don't have xcode on this computer so I just made screen in paint.

Community
  • 1
  • 1
thepersonwho
  • 85
  • 1
  • 1
  • 9

2 Answers2

0

Use Following code for alert view Controller :

let alertController = UIAlertController(title: "\n", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)

    let margin:CGFloat = 8.0
    let rect = CGRectMake(margin, margin, alertController.view.bounds.size.width - margin * 4.0, 100.0)
    let customView = UITextView(frame: rect)
    customView.text = "OREDERTEXT\nOREDERTEXT"
    customView.backgroundColor = UIColor.clearColor()
    customView.font = UIFont(name: "Helvetica", size: 15)

    alertController.view.addSubview(customView)

    let somethingAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in print("something")

        print(customView.text)

    })

    alertController.addAction(somethingAction)

    self.presentViewController(alertController, animated: true, completion:{})

I hope this will helpfull for you.

Sandeep Kumar
  • 328
  • 1
  • 8
0

Try this code its working completely fine.

YOUR FIRST ALERT

let message = "BRAND : BRNAD \n MODEL : MODEL \n PRICE : 25$"
let alertController = UIAlertController(
        title: "", // This gets overridden below.
        message: message,
        preferredStyle: .Alert
 )
 let okAction = UIAlertAction(title: "OK", style: .Cancel) { _ -> Void in
 }
 alertController.addAction(okAction)
 self.presentViewController(alertController, animated: true, completion: nil)

YOUR SECOND ALERT..

let message = "BRAND : BRNAD \n MODEL : MODEL \n PRICE : 25$ \n\n\n BRAND : BRAND \n MODEL : MODEL \n PRICE : 120$ \n"
let alertController = UIAlertController(
            title: "", // This gets overridden below.
            message: message,
            preferredStyle: .Alert
)
let okAction = UIAlertAction(title: "OK", style: .Cancel) { _ -> Void in
}
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)

Himanshu Moradiya
  • 4,769
  • 4
  • 25
  • 49