Skip to content

Commit

Permalink
custom init for username on FollowerListVC
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 10, 2020
1 parent 43f3b3f commit 85d2440
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Binary file not shown.
4 changes: 1 addition & 3 deletions GHFollowers/Screens/FavoriteListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ extension FavoriteListVC: UITableViewDelegate, UITableViewDataSource {
// get the selected row of the tableView
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let favorite = favorites[indexPath.row]
let destinationVC = FollowerListVC()
destinationVC.username = favorite.login
destinationVC.title = favorite.login
let destinationVC = FollowerListVC(username: favorite.login)

navigationController?.pushViewController(destinationVC, animated: true)
}
Expand Down
13 changes: 13 additions & 0 deletions GHFollowers/Screens/FollowerListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ class FollowerListVC: UIViewController {
var dataSource: UICollectionViewDiffableDataSource<Section, Follower>!


// username is the inout text passed from the SearchVC
init (username: String) {
super.init(nibName: nil, bundle: nil)
self.username = username
title = username
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}



override func viewDidLoad() {
super.viewDidLoad()

Expand Down
8 changes: 2 additions & 6 deletions GHFollowers/Screens/SearchVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ class SearchVC: UIViewController {
// dismiss keyboard when changing view
userNameTextFiled.resignFirstResponder()

let followerListVC = FollowerListVC()
// pass the value of the input to the FollowersVC View
followerListVC.username = userNameTextFiled.text
// same for the navigation title
followerListVC.title = userNameTextFiled.text
// finally handle the navigation
let followerListVC = FollowerListVC(username: userNameTextFiled.text!)
// handle the navigation
navigationController?.pushViewController(followerListVC, animated: true)
}

Expand Down

0 comments on commit 85d2440

Please sign in to comment.