Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var chosenUserArray = [String]()
- //doneBtn只有在選到才會出現所以要做處理
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- doneBtn.isHidden = true
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "userCell") as? UserCell else {return UITableViewCell()}
- let profileImage = UIImage(named: "defaultProfileImage")
- //chosenUserArray有被選到就打勾
- if chosenUserArray.contains(emailArray[indexPath.row]){
- cell.configureCell(profileImage: profileImage!, email: emailArray[indexPath.row], isSelected: true)
- }else{
- cell.configureCell(profileImage: profileImage!, email: emailArray[indexPath.row], isSelected: false)
- }
- //還有email的部分emailArray[indexPath.row]
- return cell
- }
- //被選到就要被加到groupMemberLbl,然後要去mainstoryboard改成minimum font scale
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- guard let cell = tableView.cellForRow(at: indexPath) as? UserCell else {return}
- if chosenUserArray.contains(cell.emailLbl.text!){
- chosenUserArray.append(cell.emailLbl.text!)
- groupMemberLbl.text = chosenUserArray.joined(separator: ", ")
- doneBtn.isHidden = false
- }else{
- chosenUserArray = chosenUserArray.filter({ $0 != cell.emailLbl.text!})
- if chosenUserArray.count >= 1 {
- groupMemberLbl.text = chosenUserArray.joined(separator: ", ")
- }else{
- groupMemberLbl.text = "add people to your group"
- doneBtn.isHidden = true
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment