I am trying to change the background color of a scroll button to delete in my table view. I looked at some examples of Objective-C, but I could not translate them into Swift.
This is my code at the moment:
var cellDeleteBackground = UIView() cellDeleteBackground.backgroundColor = UIColor.greenColor() cell.editingAccessoryView = cellDeleteBackground
I have it in cellForRowAtIndexPath, but at the moment it is crashing with the error "terminates with an uncaught exception of type NSException"
Can this code interfere?
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()
source share