I have a view with 2 buttons (active and inactive) and a table view to show all my users. I want how can I load the related data if the user clicks one of the buttons using show active/inactive users?
import UIKit
class ViewController: UIViewController,UITableViewDataSource, UISearchBarDelegate {
var users:[User] = []
let user1 = User(username: "user1",email: "[email protected]",active: true)
let user2 = User(username: "user2",email: "[email protected]",active: true)
let user3 = User(username: "user3",email: "[email protected]",active: false)
@IBOutlet weak var btnActiveUser: UIButton!
@IBOutlet weak var btnInActiveUser: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
users.append(user1)
users.append(user2)
users.append(user3)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return users.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = "this cell index for \(users[indexPath.row].username) "
return cell
}
@IBAction func ActionShowActiveUsers(_ sender: Any) {
let activeUser = users.filter( { return $0.active == true } )
print(activeUser.count)
}
@IBAction func btnShowInActiveUser(_ sender: Any) {
let inactiveUser = users.filter( { return $0.active == false } )
print(inactiveUser.count)
}
}