@@ -139,6 +139,8 @@ - (void)menuStateEventOccurred:(NSNotification *)notification {
139139 }
140140}
141141
142+
143+ #pragma mark - DataSource Methods
142144/* *
143145 * Update the feeds in the menu when a user begins or ends a search
144146 */
@@ -157,32 +159,57 @@ - (void)searchFieldDidChange
157159
158160 // Add custom feed to the searchFeeds
159161 [searchedFeeds addObject: customFeed];
162+
163+ // Update the searchFeed datasource
164+ [searchFeedDataSource updateWithFeeds: searchedFeeds];
165+ [self updateSearchFeedDataSource ];
160166 } else {
161167 // Return feeds from the API similar to user input
162168 // Add these feeds to the searchFeed datasource
163169
164170 [Feed requestFeedsByName: self .textField_searchInput.text
165171 success: ^(id responseData, NSInteger httpStatus){
166- NSLog (@" Search for feeds successful" );
172+ NSDictionary *feeds = [responseData objectForKey: @" feeds" ];
173+ for ( NSDictionary *feed in feeds){
174+ [searchedFeeds addObject: feed];
175+ }
176+ // Update the searchFeed datasource
177+ [searchFeedDataSource updateWithFeeds: searchedFeeds];
178+ [self updateSearchFeedDataSource ];
167179 }
168180 failure: ^(id responseData, NSInteger httpStatus, NSError *error){
169181 NSLog (@" Error searching for feeds" );
170182 }];
171183 }
172-
173- // Switch to the searchFeed datasource and update the table
174- [searchFeedDataSource updateWithFeeds: searchedFeeds];
175- self.tableView_feeds .dataSource = searchFeedDataSource;
176-
177- // Reload the table with new searchFeeds
178- [self .tableView_feeds reloadData ];
179184 } else {
180185 // Switch to the userFeeds datasource
181- self.tableView_feeds .dataSource = userFeedDataSource;
182- [self .tableView_feeds reloadData ];
186+ [self updateUserFeedDataSource ];
183187 }
184188}
185189
190+ /* *
191+ * Switch to and reload the menu from the searchFeedDataSource
192+ */
193+ - (void )updateSearchFeedDataSource
194+ {
195+ // Switch to the searchFeed datasource
196+ self.tableView_feeds .dataSource = searchFeedDataSource;
197+
198+ // Reload the table with new searchFeeds
199+ [self .tableView_feeds reloadData ];
200+ }
201+
202+ /* *
203+ * Switch to and reload the menu from the userFeedDataSource
204+ */
205+ - (void )updateUserFeedDataSource
206+ {
207+ // Switch to the searchFeed datasource
208+ self.tableView_feeds .dataSource = userFeedDataSource;
209+
210+ // Reload the table with new searchFeeds
211+ [self .tableView_feeds reloadData ];
212+ }
186213
187214#pragma mark - Count Methods
188215/* *
0 commit comments