我创建了一个普通的段控制器,它有两个类别,分别是1类和2类。现在我添加了按钮,它将我推送到新视图控制器以添加项目。当点击完成按钮添加项目时,我有一个警报控制器,显示我必须保存项目的类别。但我不知道如何在特定细分中获得该项目。如果有人可以帮忙。 感谢
@IBAction func done(sender: AnyObject) {
if let item = itemToEdit {
item.text = textField.text!
item.dateTime = dateTime
textField.becomeFirstResponder()
//item.text = textAreaDescription.text!
//textAreaDescription.becomeFirstResponder()
delegate?.itemDetailViewController(self, didFinishEditingItem: item)
} else {
let alertController = UIAlertController(title: "Choose Category", message: "Choose Category To Save Your Item.", preferredStyle: .Alert)
let toDo = UIAlertAction(title: "Category 1", style: .Default) { (action) in
let item = NoToDoItem()
item.text = self.textField.text!
//item.text = textAreaDescription.text!
item.dateTime = self.dateTime
self.delegate?.itemDetailViewController(self, didFinishAddingItem: item)
}
alertController.addAction(toDo)
let notSure = UIAlertAction(title: "Category 2", style: .Default){ (action) in
let notSureItem = NotSureItem()
notSureItem.text = self.textField.text!
//item.text = textAreaDescription.text!
notSureItem.dateTime = self.dateTime
self.delegate?.itemDetailViewController(self, didFinishAddingNotSureItem: notSureItem)
}
alertController.addAction(notSure)
presentViewController(alertController, animated: true, completion: nil)
}
}
答案 0 :(得分:0)
使用commitEditingstyle,然后当您滑动时,您的单元格仍会显示“删除”按钮。请改用editStyleForRowAtIndexPath :.将if语句放入以测试选择哪个段,并相应地返回UITableViewCellEditingStyle.None(以禁用滑动以删除)或.Delete(以启用滑动删除)。如果您希望能够通过将表视图置于编辑模式来删除单元格,那么还要测试tableView.editing以确定是否使用.Delete或.None。