我依次有2 UIAlertController
。我想要的是,在显示1º之后,如果用户单击2个选项中的一个,它将仅显示第二个。现在显示1ºUIAlertControllers
并且不显示第二个Block1
。
代码很大,但我已对Block2
名为func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let pratos = queryArray[indexPath.row] as PFObject
var confirmar = 0
//BLOCK1
//Pergunta o tipo de entrega
let actionSheetController: UIAlertController = UIAlertController(title: "Selecione o método de entrega", message: "", preferredStyle: .ActionSheet)
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancelar", style: .Cancel) { action -> Void in
}
actionSheetController.addAction(cancelAction)
let takePictureAction: UIAlertAction = UIAlertAction(title: "Take Away", style: .Default) { action -> Void in
confirmar = 1
}
actionSheetController.addAction(takePictureAction)
let choosePictureAction: UIAlertAction = UIAlertAction(title: "Entrega ao domicílio", style: .Default) { action -> Void in
confirmar = 2
}
actionSheetController.addAction(choosePictureAction)
self.presentViewController(actionSheetController, animated: true, completion: nil)
println("Hello")
//BLOCK2
if confirmar == 1 || confirmar == 2 {
//Confirma se pretende comprar
var loginTextField: UITextField?
let alertController = UIAlertController(title: "Deseja continuar?", message: "A sua encomenda será processada.", preferredStyle: .Alert)
var preco = pratos.objectForKey("Preco") as! String
let ok = UIAlertAction(title: "Comprar \(preco)€" , style: .Default, handler: { (action) -> Void in
var Transacao = PFObject(className:"Transacao")
Transacao["pointerUser"] = PFUser.currentUser()
Transacao["pointerRestaurante"] = self.restauranteRow
Transacao["pointerProduto"] = pratos
Transacao["entrega"] = confirmar
Transacao.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
self.performSegueWithIdentifier("compraEfectuada", sender: self)
} else {
// There was a problem, check error.description
}
}
})
let cancel = UIAlertAction(title: "Cancelar", style: .Cancel) { (action) -> Void in
println("Cancel Button Pressed")
}
alertController.addAction(ok)
alertController.addAction(cancel)
presentViewController(alertController, animated: true, completion: nil)
}
}
和{{1}}
我该怎么做?
{{1}}
答案 0 :(得分:4)
目前,在tableview的函数中创建了UIAlertController
两个if
。当用户单击它时,tableview委托会触发此函数。由于整个功能在第一个警报控制器出现之前执行,因此无法创建第二个。所以你的UIAlertController
陈述总是错误的。
将第二个confirmer
放在一个单独的函数中。不是将func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//BLOCK1
//Pergunta o tipo de entrega
alertOne()
}
func alertOne() {
//BLOCK1
let actionSheetController: UIAlertController = UIAlertController(title: "Selecione o método de entrega", message: "", preferredStyle: .ActionSheet)
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancelar", style: .Cancel) { action -> Void in
}
actionSheetController.addAction(cancelAction)
let takePictureAction: UIAlertAction = UIAlertAction(title: "Take Away", style: .Default) { action -> Void in
alertTwo(1)
}
actionSheetController.addAction(takePictureAction)
let choosePictureAction: UIAlertAction = UIAlertAction(title: "Entrega ao domicílio", style: .Default) { action -> Void in
alertTwo(2)
}
actionSheetController.addAction(choosePictureAction)
self.presentViewController(actionSheetController, animated: true, completion: nil)
}
func alertTwo(confirmar:Int) {
//BLOCK2
let pratos = queryArray[indexPath.row] as PFObject
//Confirma se pretende comprar
var loginTextField: UITextField?
let alertController = UIAlertController(title: "Deseja continuar?", message: "A sua encomenda será processada.", preferredStyle: .Alert)
var preco = pratos.objectForKey("Preco") as! String
let ok = UIAlertAction(title: "Comprar \(preco)€" , style: .Default, handler: { (action) -> Void in
var Transacao = PFObject(className:"Transacao")
Transacao["pointerUser"] = PFUser.currentUser()
Transacao["pointerRestaurante"] = self.restauranteRow
Transacao["pointerProduto"] = pratos
Transacao["entrega"] = confirmar
Transacao.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
self.performSegueWithIdentifier("compraEfectuada", sender: self)
} else {
// There was a problem, check error.description
}
}
})
let cancel = UIAlertAction(title: "Cancelar", style: .Cancel) { (action) -> Void in
println("Cancel Button Pressed")
}
alertController.addAction(ok)
alertController.addAction(cancel)
self.presentViewController(alertController, animated: true, completion: nil)
}
设置为1或2,而是触发相应的功能。然后它会工作。
Dim objWdDoc As Word.Document
Dim objWord As Word.Application
Dim sDesktop As String = Environment.GetEnvironmentVariable("userprofile") & "\Desktop\"
objWord = CreateObject("Word.Application")
objWdDoc = objWord.Documents.Open(sDesktop & "testdocument.doc")
objWord.Visible = True
'Select Printer
objWord.ActivePrinter = "Fax"
'Print to Tiff
objWdDoc.PrintOut(Range:=WdPrintOutRange.wdPrintAllDocument, _
OutputFileName:=sDesktop & "test.tiff", _
Item:=WdPrintOutItem.wdPrintDocumentContent, _
PrintToFile:=True)
'Close Document
objWdDoc.Close()
'Close Word
objWord.Quit()
'General Cleanup
objWdDoc = Nothing
objWord = Nothing