@@ -184,21 +184,18 @@ class ScheduleTableViewController: UITableViewController {
184184 }
185185
186186 // Configure favorite accessory
187-
188- // @TODO: Set toggle functionality
189- // if isFavorite {
190- // cell.accessoryView = UIImageView(image: UIImage(named: "filledStar"))
191-
192187 let favButton = FavoriteButton ( type: . custom)
193- favButton . setImage ( UIImage ( named : " filledStar " ) , for : . normal )
188+ // Set images
194189 favButton. addTarget ( self , action: #selector( favoriteTapped ( sender: ) ) , for: . touchUpInside)
195- favButton. tag = indexPath. row
196190 cell. accessoryView = favButton
197191 // Set custom properties
198192 favButton. section = indexPath. section
199193 favButton. row = indexPath. row
200194 favButton. sizeToFit ( )
201195
196+ // Now, toggle the stars that are favorited
197+ favButton. isSelected = isFavorite
198+
202199 // Confgure bubble
203200 cell. bubbleColor = UIColor . clear
204201 cell. bubbleWidth = 20.0
@@ -221,19 +218,25 @@ class ScheduleTableViewController: UITableViewController {
221218 // we use a subclassed UIButton, FavoriteButton, so we know what exact
222219 // event was pressed. (row is section-dependent)
223220 @objc func favoriteTapped( sender: UIButton ) {
221+
222+ // Reject if improper call
224223 guard let favButton = sender as? FavoriteButton else {
225224 MessageHandler . showInvalidFavoriteButtonError ( )
226225 return
227226 }
228- print ( " Tapped star at section \( favButton. section!) , \( favButton. row!) " )
229227
230- // @TODO: Obvs read/write to/from server, but also:
231- // @TODO: Change local data model, look for a table view delegate
232- // @TODO: Check if margin updates when using forked TimelineTableViewCell eventually
233- }
228+ // Update view
229+ // (FavoriteButton subclass handles this condition)
230+ favButton. isSelected = !favButton. isSelected
231+
232+ // Update model
233+ // (We handle this condition!)
234+ sampleData [ favButton. section!] ![ favButton. row!] . isFavorite = favButton. isSelected
235+
236+ // @TODO: Handle updating favorite with server
237+ // @TODO: Handle notifying users on their favorited events
234238
235- override func tableView( _ tableView: UITableView , accessoryButtonTappedForRowWith indexPath: IndexPath ) {
236- print ( " defualt accButtonTapped: \( indexPath) " )
239+ print ( " User did something to \( sampleData [ favButton. section!] ![ favButton. row!] . title) " )
237240 }
238241
239242
0 commit comments