99#import " CSMenuSearchFeedDataSource.h"
1010#import " CSUserFeedCell.h"
1111#import " Feed.h"
12+ #import " FeedItem.h"
1213#import " UIImageView+AFNetworking.h"
1314
1415@implementation CSMenuSearchFeedDataSource
@@ -30,7 +31,8 @@ - (id)init
3031}
3132
3233/* *
33- * Sets the feeds to those returned by the search
34+ * Sets the feeds to those returned by the search API or
35+ * The custom feed being created by the user
3436 */
3537- (void )updateWithFeeds : (NSMutableSet *)feeds
3638{
@@ -107,6 +109,10 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
107109 {
108110 Feed *toDelete = [self .feeds allObjects ][indexPath.row];
109111
112+ [self .feeds removeObject: toDelete];
113+ [tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation: UITableViewRowAnimationFade];
114+
115+ for ( FeedItem *item in toDelete.feedItems ) [item deleteEntity ];
110116 [toDelete deleteEntity ];
111117
112118 [[NSManagedObjectContext defaultContext ] saveToPersistentStoreAndWait ];
@@ -118,12 +124,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
118124 */
119125- (UITableViewCellEditingStyle) tableView : (UITableView *)tableView editingStyleForRowAtIndexPath : (NSIndexPath *)indexPath
120126{
121- if (!tableView.isEditing )
122- {
123- return UITableViewCellEditingStyleNone;
124- }
125-
126- if (indexPath.section == 0 && indexPath.row == [self tableView: tableView numberOfRowsInSection: 0 ] - 1 )
127+ if ( indexPath.row == [_feeds count ] )
127128 {
128129 return UITableViewCellEditingStyleInsert;
129130 }
0 commit comments