Ho cercato di cambiare il colore dello sfondo del pulsante di scorrimento per eliminare nella mia vista tabella. Ho dato un'occhiata ad alcuni esempi di Objective-C ma non sono stato in grado di tradurli in Swift.Cambia colore dello sfondo da strisciare a Elimina in Swift
Questo è il mio codice in questo momento:
var cellDeleteBackground = UIView()
cellDeleteBackground.backgroundColor = UIColor.greenColor()
cell.editingAccessoryView = cellDeleteBackground
Ho questo in cellForRowAtIndexPath, ma al momento si blocca con l'errore 'termina con eccezione non identificata di tipo NSException'
Potrebbe questo codice sia interferire?
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
if tableView == self.searchDisplayController?.searchResultsTableView {
return false
} else {
return true
}
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
if tableView == self.searchDisplayController?.searchResultsTableView {
UITableViewCellEditingStyle.None
} else {
var valueToRemove: AnyObject! = unformatted.objectAtIndex(indexPath.row)
if images.objectAtIndex(indexPath.row) as NSObject == 0 {
totalSpendingsCounter = totalSpendingsCounter - Double(valueToRemove as NSNumber)
NSUserDefaults.standardUserDefaults().setDouble(totalSpendingsCounter, forKey: "spendingsCounter")
} else if images.objectAtIndex(indexPath.row) as NSObject == 1 {
totalCreditCounter = totalCreditCounter - Double(valueToRemove as NSNumber)
NSUserDefaults.standardUserDefaults().setDouble(totalCreditCounter, forKey: "creditCounter")
}
currencyDouble = NSUserDefaults.standardUserDefaults().doubleForKey("currencyCounter")
currentBudgetCalculation = currencyDouble + totalCreditCounter - totalSpendingsCounter
newTransactionEntered = true
var formatter = NSNumberFormatter()
formatter.numberStyle = .CurrencyStyle
formatter.locale = NSLocale.currentLocale() // This is the default
var formattedNumberCurrent = formatter.stringFromNumber(currentBudgetCalculation)
var defaults = NSUserDefaults(suiteName: "group.AffordIt")
defaults.setObject(formattedNumberCurrent, forKey: "currentBudgetWidget")
defaults.setObject(newTransactionEntered, forKey: "new")
values.removeObjectAtIndex(indexPath.row)
images.removeObjectAtIndex(indexPath.row)
names.removeObjectAtIndex(indexPath.row)
dates.removeObjectAtIndex(indexPath.row)
unformatted.removeObjectAtIndex(indexPath.row)
notes.removeObjectAtIndex(indexPath.row)
NSUserDefaults.standardUserDefaults().setObject(names, forKey: "names")
NSUserDefaults.standardUserDefaults().setObject(values, forKey: "values")
NSUserDefaults.standardUserDefaults().setObject(dates, forKey: "dates")
NSUserDefaults.standardUserDefaults().setObject(unformatted, forKey: "unformatted")
NSUserDefaults.standardUserDefaults().setObject(images, forKey: "images")
NSUserDefaults.standardUserDefaults().setObject(notes, forKey: "notes")
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}
}
Grazie per la risposta comunque anche questo sembra mandare in crash la mia app con lo stesso errore. Ho aggiornato la mia domanda con un altro codice nel caso si tratti di un problema. – user3746428
Ulteriori informazioni sull'eccezione sono necessarie. Assicurati di avere punti di interruzione sulle eccezioni: http://blog.manbolo.com/2012/01/23/xcode-tips-1-break-on-exceptions – Kirsteins
Si scopre che non era correlato al codice che hai postato e funziona bene. Molte grazie! – user3746428