I have implemented a Detail Disclosure Button on my table view cell to edit existing texts in the cells. But the problem is that when I click on the Detail Disclosure Button it shows the existing text field but without any 'Edit' and 'Cancel' bar button items on the top. I have given the segue identifier name as 'EditItem'. I also have another segue which is named 'AddItem' that works properly and shows 'Edit' and 'Cancel' bar button item. I have checked the code many times to find out the problem but didn't find any solution. I want to know how to fix this problem.
I'm using Xcode 6 beta 6 SDK.
Your problem is that you are not adding the item the same way as you are editing the item. Look at this:
if ([segue.identifier isEqualToString:@"AddItem"]){
UINavigationController *navigation = segue.destinationViewController;
AddItemViewController *controller =(AddItemViewController *) navigation.topViewController;
controller.delegate = self;
} else if ([segue.identifier isEqualToString:@"EditItem"]){
UINavigationController *navigation = segue.destinationViewController;
AddItemViewController *controller = (AddItemViewController *)navigation;
controller.delegate = self;
//
NSIndexPath *indexpath = [self.tableView indexPathForCell:sender];
controller.itemToEdit = _items[indexpath.row];
}
Notice that for the AddItem
segue you are getting the view controller like this:
AddItemViewController *controller =(AddItemViewController *) navigation.topViewController;
But for the EditItem
segue you are getting it like this:
AddItemViewController *controller =(AddItemViewController *) navigation;
In your storyboard, the AddItem
segue is connected to a navigation controller, which is then connected to your AddViewController
, but the EditItem
segue goes directly to the AddViewController
.
Connecting EditItem
to the same navigation controller AddItem
is connected to should fix your problem.