0

I had created a normal segment controller which has two category, category 1 and 2 respectively. Now I have add button, which push me to the new view controller to add an item. When clicking on done button for adding an item I have an alert controller which show the category in which I have to save the item. But I don't know how to get that item in particular segment. If anyone can help. Thanks

@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)

    }
}
shahin ali agharia
  • 1,629
  • 4
  • 21
  • 36

1 Answers1

0

use commitEditingstyle, then your cells will still display the Delete button when you swipe. Use editingStyleForRowAtIndexPath: instead. Put an if statement in to test which segment is selected, and return UITableViewCellEditingStyle.None (to disable swipe to delete) or .Delete (to enable swipe to delete) accordingly. If you want to be able to delete the cells by putting the table view into editing mode, then also test tableView.editing to determine whether to use .Delete or .None.

Ashwini
  • 337
  • 1
  • 5
  • 10