Swift & Firebase Follow / Unfollow ButtonHow to call Objective-C code from Swift#pragma mark in Swift?Swift for loop: for index, element in array?Swift Beta performance: sorting arraysExpand and Collapse tableview cellsUpdate or reload UITableView after completion of delete action on detail viewTableView not displaying text with JSON data from API callSwift Error - Use of undeclared type 'cell' - Collection ViewSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift
Is it possible to have the age of the universe be unknown?
How do governments keep track of their issued currency?
Did Milano or Benatar approve or comment on their namesake MCU ships?
Is using haveibeenpwned to validate password strength rational?
Arriving at the same result with the opposite hypotheses
Fail to return int value from a function
Teaching a class likely meant to inflate the GPA of student athletes
Does a scale have more than seven chords?
Why we don’t make use of the t-distribution for constructing a confidence interval for a proportion?
You have (3^2 + 2^3 + 2^2) Guesses Left. Figure out the Last one
Why doesn't Adrian Toomes give up Spider-Man's identity?
What is the purpose of the goat for Azazel, as opposed to conventional offerings?
What ways have you found to get edits from non-LaTeX users?
How to hide an urban landmark?
Overlapping String-Blocks
Has there been a multiethnic Star Trek character?
Which languages would be most useful in Europe at the end of the 19th century?
Meaning of 'lose their grip on the groins of their followers'
Is it legal for a bar bouncer to confiscate a fake ID
How can I make some of my chapters "come to life"?
Jargon request: "Canonical Form" of a word
How to hide rifle during medieval town entrance inspection?
How is John Wick 3 a 15 certificate?
Bent Peugeot Carbolite 103 Frame
Swift & Firebase Follow / Unfollow Button
How to call Objective-C code from Swift#pragma mark in Swift?Swift for loop: for index, element in array?Swift Beta performance: sorting arraysExpand and Collapse tableview cellsUpdate or reload UITableView after completion of delete action on detail viewTableView not displaying text with JSON data from API callSwift Error - Use of undeclared type 'cell' - Collection ViewSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am currently building an application using firebase, i have a follow button which followers the user or unfollows the user if already following.
After i cannot follow the user, when i click the button the data adds into firebase and then gets deleted again..
when i run the app again eveyything works perfectly find apart from the same bug when i am following again
this is my firebase database [FirebaseDatabase][1]
This is my code
var follower = false
override func viewDidLoad()
super.viewDidLoad()
refreshControl.addTarget(self, action: #selector(refresh), for: UIControl.Event.valueChanged)
self.tableView.addSubview(refreshControl)
if guest == true
buttonRight.setImage(UIImage(named:"icons8-user-menu-male-filled-30"), for: .normal)
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
NotificationCenter.default.addObserver(self, selector: #selector(self.filterRefresh(_:)), name: NSNotification.Name(rawValue: "followRefresh"), object: nil)
else
if let user = Auth.auth().currentUser
if !user.isEmailVerified
let alert = JDropDownAlert()
alert.alertWith("Please Verify your Email Address")
alert.didTapBlock =
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "verify") as! VerifyEmailViewController
let navController = UINavigationController(rootViewController: myVC)
self.navigationController?.present(navController, animated: true, completion: nil)
else
print ("Email verified. Signing in...")
firebaseControllerHandle.delegate = self
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserInfo(uid:(Auth.auth().currentUser?.uid)!)
firebaseControllerHandle.getUserProducts(userID: (Auth.auth().currentUser?.uid)!)
self.navigationController?.navigationBar.shadowImage = UIImage()
@objc func filterRefresh(_ notification:Notification)
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
@objc func refresh()
// Code to refresh table view
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "refresh"), object: nil)
// `default` is now a property, not a method call
if guest == true
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
else
print("ont")
refreshControl.endRefreshing()
func loadFollowings(followings: [String])
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "Following") as! FollowingsViewController
let navController = UINavigationController(rootViewController: myVC)
self.navigationController?.present(navController, animated: true, completion: nil)
func numberOfSections(in tableView: UITableView) -> Int
return 1
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return 2
func userInfo(user: UserModel)
self.user = user
if guest == true
self.guestUser = user
follower = false
for x in user.followers
if x == Auth.auth().currentUser?.uid
follower = true
else
follower = false
print("guest")
self.tableView.reloadData()
else
//self.user = user
print("test")
self.tableView.reloadData()
var follower = false
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
switch indexPath.row
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "profile", for: indexPath) as! profileCell
if guest == true
cell.guestUserID = guestuid
if follower == true
cell.button.setTitle("Following", for: .normal)
cell.buttonChecked = true
else
cell.button.setTitle("Follow", for: .normal)
cell.buttonChecked = false
cell.bio.text = guestUser.bio
cell.sendMessageButton.setTitle("Send Message", for: .normal)
else
let url = URL(string: user.profilePhoto)
print(user.profilePhoto)
cell.img.kf.setImage(with: url)
cell.bio.text = user.bio
cell.button.setTitle("Edit Profile", for: .normal)
cell.sendMessageButton.setTitle("My Orders", for: .normal)
cell.fullname.text = user.fullName
cell.delegate = self
return cell
case 1 :
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! profileInfo
return cell
default:
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! profileCell
return cell
```
```
this is my cell button action
@IBAction func followedit(_ sender: Any)
if buttonChecked == true
print("REMOVE FOLLOW")
self.delegate?.myTableDelegate()
let appearance = SCLAlertView.SCLAppearance(
showCloseButton: false, showCircularIcon: false
)
// Initialize SCLAlertView using custom Appearance
let alert = SCLAlertView(appearance: appearance)
alert.addButton("Unfollow", backgroundColor: UIColor.black, textColor: UIColor.white)
let userRef = self.ref.child("Users").child(CurrentUserID.uid).child("Followings")
let query = userRef.queryOrdered(byChild: "userid").queryEqual(toValue: self.guestUserID)
let guestRemove = self.ref.child("Users").child(self.guestUserID).child("Followers")
let guestRemoveQuery = guestRemove.queryOrdered(byChild: "userid").queryEqual(toValue: CurrentUserID.uid)
guestRemoveQuery.observe(.childAdded, with: snapshot in
if snapshot.exists()
snapshot.ref.removeValue()
else
print("snapshot doesn't exist")
)
query.observe(.childAdded, with: snapshot in
if snapshot.exists()
snapshot.ref.removeValue()
else
print("snapshot doesn't exist")
)
alert.addButton("Cancel", backgroundColor: UIColor.black, textColor: UIColor.white)
alert.dismiss(animated: true, completion: nil)
alert.showEdit("Unfollow (guestUserID)", subTitle: "Are you sure you want to unfollow (guestUserID)?")
else
print("ADD FOLLOW")
ref.child("Users").child(CurrentUserID.uid).child("Followings").childByAutoId().setValue(["userid" : guestUserID])
ref.child("Users").child(guestUserID).child("Followers").childByAutoId().setValue(["userid" : CurrentUserID.uid])
print(buttonChecked)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "followRefresh"), object: nil)
```
[1]: https://i.stack.imgur.com/5sMqa.png
swift firebase
add a comment |
I am currently building an application using firebase, i have a follow button which followers the user or unfollows the user if already following.
After i cannot follow the user, when i click the button the data adds into firebase and then gets deleted again..
when i run the app again eveyything works perfectly find apart from the same bug when i am following again
this is my firebase database [FirebaseDatabase][1]
This is my code
var follower = false
override func viewDidLoad()
super.viewDidLoad()
refreshControl.addTarget(self, action: #selector(refresh), for: UIControl.Event.valueChanged)
self.tableView.addSubview(refreshControl)
if guest == true
buttonRight.setImage(UIImage(named:"icons8-user-menu-male-filled-30"), for: .normal)
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
NotificationCenter.default.addObserver(self, selector: #selector(self.filterRefresh(_:)), name: NSNotification.Name(rawValue: "followRefresh"), object: nil)
else
if let user = Auth.auth().currentUser
if !user.isEmailVerified
let alert = JDropDownAlert()
alert.alertWith("Please Verify your Email Address")
alert.didTapBlock =
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "verify") as! VerifyEmailViewController
let navController = UINavigationController(rootViewController: myVC)
self.navigationController?.present(navController, animated: true, completion: nil)
else
print ("Email verified. Signing in...")
firebaseControllerHandle.delegate = self
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserInfo(uid:(Auth.auth().currentUser?.uid)!)
firebaseControllerHandle.getUserProducts(userID: (Auth.auth().currentUser?.uid)!)
self.navigationController?.navigationBar.shadowImage = UIImage()
@objc func filterRefresh(_ notification:Notification)
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
@objc func refresh()
// Code to refresh table view
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "refresh"), object: nil)
// `default` is now a property, not a method call
if guest == true
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
else
print("ont")
refreshControl.endRefreshing()
func loadFollowings(followings: [String])
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "Following") as! FollowingsViewController
let navController = UINavigationController(rootViewController: myVC)
self.navigationController?.present(navController, animated: true, completion: nil)
func numberOfSections(in tableView: UITableView) -> Int
return 1
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return 2
func userInfo(user: UserModel)
self.user = user
if guest == true
self.guestUser = user
follower = false
for x in user.followers
if x == Auth.auth().currentUser?.uid
follower = true
else
follower = false
print("guest")
self.tableView.reloadData()
else
//self.user = user
print("test")
self.tableView.reloadData()
var follower = false
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
switch indexPath.row
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "profile", for: indexPath) as! profileCell
if guest == true
cell.guestUserID = guestuid
if follower == true
cell.button.setTitle("Following", for: .normal)
cell.buttonChecked = true
else
cell.button.setTitle("Follow", for: .normal)
cell.buttonChecked = false
cell.bio.text = guestUser.bio
cell.sendMessageButton.setTitle("Send Message", for: .normal)
else
let url = URL(string: user.profilePhoto)
print(user.profilePhoto)
cell.img.kf.setImage(with: url)
cell.bio.text = user.bio
cell.button.setTitle("Edit Profile", for: .normal)
cell.sendMessageButton.setTitle("My Orders", for: .normal)
cell.fullname.text = user.fullName
cell.delegate = self
return cell
case 1 :
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! profileInfo
return cell
default:
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! profileCell
return cell
```
```
this is my cell button action
@IBAction func followedit(_ sender: Any)
if buttonChecked == true
print("REMOVE FOLLOW")
self.delegate?.myTableDelegate()
let appearance = SCLAlertView.SCLAppearance(
showCloseButton: false, showCircularIcon: false
)
// Initialize SCLAlertView using custom Appearance
let alert = SCLAlertView(appearance: appearance)
alert.addButton("Unfollow", backgroundColor: UIColor.black, textColor: UIColor.white)
let userRef = self.ref.child("Users").child(CurrentUserID.uid).child("Followings")
let query = userRef.queryOrdered(byChild: "userid").queryEqual(toValue: self.guestUserID)
let guestRemove = self.ref.child("Users").child(self.guestUserID).child("Followers")
let guestRemoveQuery = guestRemove.queryOrdered(byChild: "userid").queryEqual(toValue: CurrentUserID.uid)
guestRemoveQuery.observe(.childAdded, with: snapshot in
if snapshot.exists()
snapshot.ref.removeValue()
else
print("snapshot doesn't exist")
)
query.observe(.childAdded, with: snapshot in
if snapshot.exists()
snapshot.ref.removeValue()
else
print("snapshot doesn't exist")
)
alert.addButton("Cancel", backgroundColor: UIColor.black, textColor: UIColor.white)
alert.dismiss(animated: true, completion: nil)
alert.showEdit("Unfollow (guestUserID)", subTitle: "Are you sure you want to unfollow (guestUserID)?")
else
print("ADD FOLLOW")
ref.child("Users").child(CurrentUserID.uid).child("Followings").childByAutoId().setValue(["userid" : guestUserID])
ref.child("Users").child(guestUserID).child("Followers").childByAutoId().setValue(["userid" : CurrentUserID.uid])
print(buttonChecked)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "followRefresh"), object: nil)
```
[1]: https://i.stack.imgur.com/5sMqa.png
swift firebase
1
It's better you don't add your entire code. Just add Follow and Unfollow Button Events.
– Dhruv Khatri
Mar 24 at 19:27
I fixed it, it was the .childadded firebase query
– GRattab
Mar 24 at 21:14
add a comment |
I am currently building an application using firebase, i have a follow button which followers the user or unfollows the user if already following.
After i cannot follow the user, when i click the button the data adds into firebase and then gets deleted again..
when i run the app again eveyything works perfectly find apart from the same bug when i am following again
this is my firebase database [FirebaseDatabase][1]
This is my code
var follower = false
override func viewDidLoad()
super.viewDidLoad()
refreshControl.addTarget(self, action: #selector(refresh), for: UIControl.Event.valueChanged)
self.tableView.addSubview(refreshControl)
if guest == true
buttonRight.setImage(UIImage(named:"icons8-user-menu-male-filled-30"), for: .normal)
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
NotificationCenter.default.addObserver(self, selector: #selector(self.filterRefresh(_:)), name: NSNotification.Name(rawValue: "followRefresh"), object: nil)
else
if let user = Auth.auth().currentUser
if !user.isEmailVerified
let alert = JDropDownAlert()
alert.alertWith("Please Verify your Email Address")
alert.didTapBlock =
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "verify") as! VerifyEmailViewController
let navController = UINavigationController(rootViewController: myVC)
self.navigationController?.present(navController, animated: true, completion: nil)
else
print ("Email verified. Signing in...")
firebaseControllerHandle.delegate = self
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserInfo(uid:(Auth.auth().currentUser?.uid)!)
firebaseControllerHandle.getUserProducts(userID: (Auth.auth().currentUser?.uid)!)
self.navigationController?.navigationBar.shadowImage = UIImage()
@objc func filterRefresh(_ notification:Notification)
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
@objc func refresh()
// Code to refresh table view
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "refresh"), object: nil)
// `default` is now a property, not a method call
if guest == true
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
else
print("ont")
refreshControl.endRefreshing()
func loadFollowings(followings: [String])
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "Following") as! FollowingsViewController
let navController = UINavigationController(rootViewController: myVC)
self.navigationController?.present(navController, animated: true, completion: nil)
func numberOfSections(in tableView: UITableView) -> Int
return 1
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return 2
func userInfo(user: UserModel)
self.user = user
if guest == true
self.guestUser = user
follower = false
for x in user.followers
if x == Auth.auth().currentUser?.uid
follower = true
else
follower = false
print("guest")
self.tableView.reloadData()
else
//self.user = user
print("test")
self.tableView.reloadData()
var follower = false
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
switch indexPath.row
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "profile", for: indexPath) as! profileCell
if guest == true
cell.guestUserID = guestuid
if follower == true
cell.button.setTitle("Following", for: .normal)
cell.buttonChecked = true
else
cell.button.setTitle("Follow", for: .normal)
cell.buttonChecked = false
cell.bio.text = guestUser.bio
cell.sendMessageButton.setTitle("Send Message", for: .normal)
else
let url = URL(string: user.profilePhoto)
print(user.profilePhoto)
cell.img.kf.setImage(with: url)
cell.bio.text = user.bio
cell.button.setTitle("Edit Profile", for: .normal)
cell.sendMessageButton.setTitle("My Orders", for: .normal)
cell.fullname.text = user.fullName
cell.delegate = self
return cell
case 1 :
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! profileInfo
return cell
default:
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! profileCell
return cell
```
```
this is my cell button action
@IBAction func followedit(_ sender: Any)
if buttonChecked == true
print("REMOVE FOLLOW")
self.delegate?.myTableDelegate()
let appearance = SCLAlertView.SCLAppearance(
showCloseButton: false, showCircularIcon: false
)
// Initialize SCLAlertView using custom Appearance
let alert = SCLAlertView(appearance: appearance)
alert.addButton("Unfollow", backgroundColor: UIColor.black, textColor: UIColor.white)
let userRef = self.ref.child("Users").child(CurrentUserID.uid).child("Followings")
let query = userRef.queryOrdered(byChild: "userid").queryEqual(toValue: self.guestUserID)
let guestRemove = self.ref.child("Users").child(self.guestUserID).child("Followers")
let guestRemoveQuery = guestRemove.queryOrdered(byChild: "userid").queryEqual(toValue: CurrentUserID.uid)
guestRemoveQuery.observe(.childAdded, with: snapshot in
if snapshot.exists()
snapshot.ref.removeValue()
else
print("snapshot doesn't exist")
)
query.observe(.childAdded, with: snapshot in
if snapshot.exists()
snapshot.ref.removeValue()
else
print("snapshot doesn't exist")
)
alert.addButton("Cancel", backgroundColor: UIColor.black, textColor: UIColor.white)
alert.dismiss(animated: true, completion: nil)
alert.showEdit("Unfollow (guestUserID)", subTitle: "Are you sure you want to unfollow (guestUserID)?")
else
print("ADD FOLLOW")
ref.child("Users").child(CurrentUserID.uid).child("Followings").childByAutoId().setValue(["userid" : guestUserID])
ref.child("Users").child(guestUserID).child("Followers").childByAutoId().setValue(["userid" : CurrentUserID.uid])
print(buttonChecked)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "followRefresh"), object: nil)
```
[1]: https://i.stack.imgur.com/5sMqa.png
swift firebase
I am currently building an application using firebase, i have a follow button which followers the user or unfollows the user if already following.
After i cannot follow the user, when i click the button the data adds into firebase and then gets deleted again..
when i run the app again eveyything works perfectly find apart from the same bug when i am following again
this is my firebase database [FirebaseDatabase][1]
This is my code
var follower = false
override func viewDidLoad()
super.viewDidLoad()
refreshControl.addTarget(self, action: #selector(refresh), for: UIControl.Event.valueChanged)
self.tableView.addSubview(refreshControl)
if guest == true
buttonRight.setImage(UIImage(named:"icons8-user-menu-male-filled-30"), for: .normal)
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
NotificationCenter.default.addObserver(self, selector: #selector(self.filterRefresh(_:)), name: NSNotification.Name(rawValue: "followRefresh"), object: nil)
else
if let user = Auth.auth().currentUser
if !user.isEmailVerified
let alert = JDropDownAlert()
alert.alertWith("Please Verify your Email Address")
alert.didTapBlock =
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "verify") as! VerifyEmailViewController
let navController = UINavigationController(rootViewController: myVC)
self.navigationController?.present(navController, animated: true, completion: nil)
else
print ("Email verified. Signing in...")
firebaseControllerHandle.delegate = self
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserInfo(uid:(Auth.auth().currentUser?.uid)!)
firebaseControllerHandle.getUserProducts(userID: (Auth.auth().currentUser?.uid)!)
self.navigationController?.navigationBar.shadowImage = UIImage()
@objc func filterRefresh(_ notification:Notification)
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
@objc func refresh()
// Code to refresh table view
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "refresh"), object: nil)
// `default` is now a property, not a method call
if guest == true
firebaseControllerHandle.delegate = self
firebaseControllerHandle.getUserInfo(uid:guestuid)
firebaseControllerHandle.userDelegate = self
firebaseControllerHandle.getUserProducts(userID: guestuid)
else
print("ont")
refreshControl.endRefreshing()
func loadFollowings(followings: [String])
let myVC = self.storyboard?.instantiateViewController(withIdentifier: "Following") as! FollowingsViewController
let navController = UINavigationController(rootViewController: myVC)
self.navigationController?.present(navController, animated: true, completion: nil)
func numberOfSections(in tableView: UITableView) -> Int
return 1
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return 2
func userInfo(user: UserModel)
self.user = user
if guest == true
self.guestUser = user
follower = false
for x in user.followers
if x == Auth.auth().currentUser?.uid
follower = true
else
follower = false
print("guest")
self.tableView.reloadData()
else
//self.user = user
print("test")
self.tableView.reloadData()
var follower = false
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
switch indexPath.row
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "profile", for: indexPath) as! profileCell
if guest == true
cell.guestUserID = guestuid
if follower == true
cell.button.setTitle("Following", for: .normal)
cell.buttonChecked = true
else
cell.button.setTitle("Follow", for: .normal)
cell.buttonChecked = false
cell.bio.text = guestUser.bio
cell.sendMessageButton.setTitle("Send Message", for: .normal)
else
let url = URL(string: user.profilePhoto)
print(user.profilePhoto)
cell.img.kf.setImage(with: url)
cell.bio.text = user.bio
cell.button.setTitle("Edit Profile", for: .normal)
cell.sendMessageButton.setTitle("My Orders", for: .normal)
cell.fullname.text = user.fullName
cell.delegate = self
return cell
case 1 :
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! profileInfo
return cell
default:
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! profileCell
return cell
```
```
this is my cell button action
@IBAction func followedit(_ sender: Any)
if buttonChecked == true
print("REMOVE FOLLOW")
self.delegate?.myTableDelegate()
let appearance = SCLAlertView.SCLAppearance(
showCloseButton: false, showCircularIcon: false
)
// Initialize SCLAlertView using custom Appearance
let alert = SCLAlertView(appearance: appearance)
alert.addButton("Unfollow", backgroundColor: UIColor.black, textColor: UIColor.white)
let userRef = self.ref.child("Users").child(CurrentUserID.uid).child("Followings")
let query = userRef.queryOrdered(byChild: "userid").queryEqual(toValue: self.guestUserID)
let guestRemove = self.ref.child("Users").child(self.guestUserID).child("Followers")
let guestRemoveQuery = guestRemove.queryOrdered(byChild: "userid").queryEqual(toValue: CurrentUserID.uid)
guestRemoveQuery.observe(.childAdded, with: snapshot in
if snapshot.exists()
snapshot.ref.removeValue()
else
print("snapshot doesn't exist")
)
query.observe(.childAdded, with: snapshot in
if snapshot.exists()
snapshot.ref.removeValue()
else
print("snapshot doesn't exist")
)
alert.addButton("Cancel", backgroundColor: UIColor.black, textColor: UIColor.white)
alert.dismiss(animated: true, completion: nil)
alert.showEdit("Unfollow (guestUserID)", subTitle: "Are you sure you want to unfollow (guestUserID)?")
else
print("ADD FOLLOW")
ref.child("Users").child(CurrentUserID.uid).child("Followings").childByAutoId().setValue(["userid" : guestUserID])
ref.child("Users").child(guestUserID).child("Followers").childByAutoId().setValue(["userid" : CurrentUserID.uid])
print(buttonChecked)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "followRefresh"), object: nil)
```
[1]: https://i.stack.imgur.com/5sMqa.png
swift firebase
swift firebase
asked Mar 24 at 18:05
GRattabGRattab
64
64
1
It's better you don't add your entire code. Just add Follow and Unfollow Button Events.
– Dhruv Khatri
Mar 24 at 19:27
I fixed it, it was the .childadded firebase query
– GRattab
Mar 24 at 21:14
add a comment |
1
It's better you don't add your entire code. Just add Follow and Unfollow Button Events.
– Dhruv Khatri
Mar 24 at 19:27
I fixed it, it was the .childadded firebase query
– GRattab
Mar 24 at 21:14
1
1
It's better you don't add your entire code. Just add Follow and Unfollow Button Events.
– Dhruv Khatri
Mar 24 at 19:27
It's better you don't add your entire code. Just add Follow and Unfollow Button Events.
– Dhruv Khatri
Mar 24 at 19:27
I fixed it, it was the .childadded firebase query
– GRattab
Mar 24 at 21:14
I fixed it, it was the .childadded firebase query
– GRattab
Mar 24 at 21:14
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326864%2fswift-firebase-follow-unfollow-button%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326864%2fswift-firebase-follow-unfollow-button%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It's better you don't add your entire code. Just add Follow and Unfollow Button Events.
– Dhruv Khatri
Mar 24 at 19:27
I fixed it, it was the .childadded firebase query
– GRattab
Mar 24 at 21:14