Guest User

Untitled

a guest
Nov 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. var chosenUserArray = [String]()
  2.  
  3. //doneBtn只有在選到才會出現所以要做處理
  4. override func viewWillAppear(_ animated: Bool) {
  5. super.viewWillAppear(animated)
  6. doneBtn.isHidden = true
  7. }
  8.  
  9. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  10. guard let cell = tableView.dequeueReusableCell(withIdentifier: "userCell") as? UserCell else {return UITableViewCell()}
  11. let profileImage = UIImage(named: "defaultProfileImage")
  12. //chosenUserArray有被選到就打勾
  13. if chosenUserArray.contains(emailArray[indexPath.row]){
  14. cell.configureCell(profileImage: profileImage!, email: emailArray[indexPath.row], isSelected: true)
  15. }else{
  16. cell.configureCell(profileImage: profileImage!, email: emailArray[indexPath.row], isSelected: false)
  17. }
  18.  
  19. //還有email的部分emailArray[indexPath.row]
  20. return cell
  21. }
  22.  
  23. //被選到就要被加到groupMemberLbl,然後要去mainstoryboard改成minimum font scale
  24. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  25. guard let cell = tableView.cellForRow(at: indexPath) as? UserCell else {return}
  26. if chosenUserArray.contains(cell.emailLbl.text!){
  27. chosenUserArray.append(cell.emailLbl.text!)
  28. groupMemberLbl.text = chosenUserArray.joined(separator: ", ")
  29. doneBtn.isHidden = false
  30. }else{
  31. chosenUserArray = chosenUserArray.filter({ $0 != cell.emailLbl.text!})
  32. if chosenUserArray.count >= 1 {
  33. groupMemberLbl.text = chosenUserArray.joined(separator: ", ")
  34. }else{
  35. groupMemberLbl.text = "add people to your group"
  36. doneBtn.isHidden = true
  37. }
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment