我将 UITableViewController 设置为在 iPad 上的弹出窗口中显示:
当我单击一行时,我会显示一条警报,以警告用户潜在的破坏性行为。我使用了新的 UIAlertController,结果如下:
弹出框变得非常小(实际上是 alertController 视图的大小)。如果我按取消,我可以看到结果:
这是我的代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var previouslySelectedCell: UITableViewCell?
if checkedIndexPath != nil {
previouslySelectedCell = tableView.cellForRowAtIndexPath(checkedIndexPath)
}
var selectedCell = tableView.cellForRowAtIndexPath(indexPath)
let selectedCurrency = PortfolioCurrencyStore.sharedStore().allCurrencies[indexPath.row]
if selectedCurrency.symbol != GlobalSettings.sharedStore().portfolioCurrency {
// Warning : changing the portfolio currency will reset the portfolio
var resetWarning = UIAlertController(title: NSLocalizedString("Currency Picker VC:AS title", comment: "Changing currency will reset portfolio"), message: nil, preferredStyle: .ActionSheet)
// destructive button
let resetAction = UIAlertAction(title: NSLocalizedString("Currency Picker VC:AS destructive", comment: "Destructive button title"), style: .Destructive, handler: { (action: UIAlertAction!) in
// Remove checkmark from the previously marked cell
previouslySelectedCell?.accessoryType = .None
// Add checkmark to the selected cell
selectedCell?.accessoryType = .Checkmark
self.checkedIndexPath = indexPath
// Animate deselection of cell
self.tableView.deselectRowAtIndexPath(indexPath, animated:true)
// Stock the portfolio currency as NSUserDefaults
GlobalSettings.sharedStore().portfolioCurrency = selectedCurrency.symbol // link between portfolioCurrency as a String and currency.symbol as the property of a Currency instance.
// Delete all items from the StockStore
StockStore.sharedStore().removeAllStocks()
println("StockStore : all entries were deleted")
// Reload tableView
self.tableView.reloadData()
})
// cancel button
let cancelAction = UIAlertAction(title: NSLocalizedString("Currency Picker VC:AS cancel", comment: "Cancel button title"), style: .Cancel, handler:nil)
resetWarning.addAction(resetAction)
resetWarning.addAction(cancelAction)
presentViewController(resetWarning, animated: true, completion: nil)
} else {
// Animate deselection of cell
tableView.deselectRowAtIndexPath(indexPath, animated:true)
}
}
我错过了什么 ?
谢谢你的帮助