Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Kieran Robinson
9,411 PointsMoving swipe to delete into detail view
In my app, i have a tableview that currently uses swipe to delete. I implemented this by following the section within the diary app with Ash Furrow. however i wish to have the delete function as a button at the bottom of the detail view. Any ideas?

Kieran Robinson
9,411 PointsI will use the diary app as an example. I have the list of diary entries on 'entryListViewController' and to remove one i currently swipe to delete. However on the 'edit' page of the diary app I would like a button at the bottom of the page to delete that entry?

Ash Furrow
Treehouse Guest TeacherAh, that's a bit trickier. Adding the button is easy, but having it do something is the hard part. You'd need to set up a callback in the delegate protocol to delete the entry, and then immediately dismiss the edit view controller. Does that make sense?

Kieran Robinson
9,411 PointsIm not quite sure what you mean, which methods would i use or remove, using the diary app as an example?

Ash Furrow
Treehouse Guest TeacherAh, right, sorry. Forgot we didn't use the delegate pattern in this case. Your code to delete would look something like:
-(void)deleteEntry {
/*delete the entry*/
/*save the context*/
/*dismiss the view controller*/
}
Shouldn't be too hard. Let me know if you run into any issues.

Kieran Robinson
9,411 PointsThank you! i will have a look now, is this still within 'entryListViewController' or the 'EntryViewController' where the button would be?

Ash Furrow
Treehouse Guest TeacherYup – in the entry view controller.

Kieran Robinson
9,411 PointsI will try it now! one last thing, i've been trying to teach myself how to add a search bar and display controller, but most of the tutorials are for older iOS versions, has anything changed in iOS 7 that would deem these tutorials useless?

Ash Furrow
Treehouse Guest TeacherNo, not really. iOS 8 changes some things, but the concepts you learn will still be relevant.

Kieran Robinson
9,411 Pointsthanks again!

Kieran Robinson
9,411 PointsHi Ash Furrow
-(void)deleteEntry {
CoreDataStack *coreDataStack = [CoreDataStack defaultStack]; DiaryEntry *entry = [self.fetchedResultsController objectAtIndexPath:indexPath];
//delete entry
[[coreDataStack managedObjectContext] deleteObject:entry];
//save context
[coreDataStack saveContext];
//dismiss view controller
[self dismissSelf];
}
also, what methods do i take out of the entryListViewController?

Kieran Robinson
9,411 Pointsnot sure why it formatted my comment that way, it won't change! hope you can still understand the method?

Ash Furrow
Treehouse Guest TeacherInteresting. That should be working. What's happening instead? Can you post a project that's not working so I can take a closer look?

Kieran Robinson
9,411 PointsAsh Furrow its working now! Thank you for your time

Ash Furrow
Treehouse Guest TeacherAnytime!
Ash Furrow
Treehouse Guest TeacherAsh Furrow
Treehouse Guest TeacherHmm. Not quite sure what you mean. Can you elaborate?