- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我一直在尝试在我的应用程序上实现“关注”功能。本质上,当用户点击“关注”按钮时,我们运行 runTransactionBlock
来更新我们存储在 Firebase 数据库中的用户及其关注帐户的整数值。 问题是我可以为用户更新计数器(比如下面例子中的 John),但是我不能为我关注的用户更新计数器(比如下面例子中的 olivia)。
目前 Firebase 节点看起来是这样的:
user_profiles{
UID1:{
name: john
following: 1 //code will update for my account
followers: 0
},
UID2:{
name: olivia
following: 0
followers: 0 //code will not update count for person i am trying to follow
我已经引用了以下内容,但是我仍然面临着让它工作的问题。如果有人可以浏览并指出正确的方向,将不胜感激。
https://www.firebase.com/docs/ios/guide/saving-data.html
Firebase database help - Swift
Upvote/Downvote system within Swift via Firebase
var guestUIDToPass = String()
var loggedInUser = AnyObject()
@IBAction func didTapFollow(sender: AnyObject) {
following()
}
func following() {
self.loggedInUser = FIRAuth.auth()?.currentUser
//updating count for user, works perfectly
self.databaseRef.child("user_profiles").child(self.loggedInUser.uid).child("following").runTransactionBlock({
(currentData:FIRMutableData!) in
var value = currentData.value as? Int
if (value == nil) {
value = 0
}
currentData.value = value! + 1
return FIRTransactionResult.successWithValue(currentData)
})
//updating count for person user is following, doesn't update firebase
self.databaseRef.child("user_profiles").child("\(self.guestUIDToPass)").child("followers").runTransactionBlock({
(currentData:FIRMutableData!) in
var value = currentData.value as? Int
if (value == nil) {
value = 0
}
currentData.value = value! + 1
return FIRTransactionResult.successWithValue(currentData)
})
}
最佳答案
尝试:-
let prntRef = FIRDatabase.database().reference().child("user_profiles").child(whomIFollowedUID).child("following")
prntRef.runTransactionBlock({ (following) -> FIRTransactionResult in
if let followNum = following.value as? Int{
following.value = followNum + 1
return FIRTransactionResult.successWithValue(following)
}else{
return FIRTransactionResult.successWithValue(following)
}
}, andCompletionBlock: {(error,completion,snap) in
print(error?.localizedDescription)
print(completion)
print(snap)
if !completion {
print("The value wasn't able to Update")
}else{
//Updated
}
})
关于ios - 关注者计数器未更新 firebase 中的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39601296/
众所周知,jQuery 的 $.post 函数非常棒,但我遇到的问题是查看页面源代码的人可以查看数据的去向,从而移向该页面进行窥探,或者,上帝禁止找到保存所有内容的文件夹。所以我的问题是,谁知道如何隐
我在下面有这个程序,它执行简单的关注/取消关注功能。一切都很好,除了当我刷新页面时,只有行中的第一个用户保留正确的关注/取消关注按钮。示例 我可以关注 user1 user2 和 user3,但是当我
我想要创建的是一个关注者/关注系统,您不是简单地关注用户,而是关注他们共享的内容部分。几乎就好像您关注的是 Twitter 的“列表”或群组而不是人员。不过,有了这个,您就可以关注/取消关注用户共享的
这个问题已经有答案了: facebook social plug-in not showing up when added dynamically (2 个回答) 已关闭 7 年前。 使用 HTML
我正在构建一个编辑器,它使用 TImage 来显示图片,并具有鼠标事件来能够在图像上绘制、移动框和调整框大小。这一切都很完美。现在我正在尝试实现使用键盘上的箭头移动选定框的功能,但是A)TImage没
我有两个问题,请记住我是一个java新手1.我有一个使用 JFrame 创建 GUI 的类。JFrame 有 2 个面板,我使用 JSplitPane 添加了 问题是我可以设法将焦点设置在所需的 JP
我目前正在使用iOS应用程序进行开发,该应用程序会从流式API捕获一些推文。因此,我使用用户名和密码进行身份验证。除此之外,我想给用户提供在Twitter上关注某些人的机会。我创建了一个UIButto
有没有办法钩入Play evolutions framework这样当它成功从 n.sql 迁移时至 n+1.sql至 n+2.sql ...,它在 Play 应用程序中调用了一些成功后 Hook (
我的 gorm 中有文本模式为多行的文本框。我必须通过 jQuery 将 css 应用到该文本框。为此,我使用了以下脚本。 $(document).ready(function() {
我在强制关注动态生成的 JQuery 对话框内容中的文本字段时遇到问题。我已经在 google 上搜索过这一点,似乎如果 Jquery 对话框设置为模式,JQuery 将“窃取”文档级别的焦点。老实说
下午,我正在使用 PHP、HTML5 和 Bootstrap。我构建了一个分为 5 个选项卡的表单,该表单中有几个必填字段。所有必需的输入字段都是“文本”,并且还标有 required="requir
我创建了一个带有 GridView 的 WPF 页面。在 GridView 中,每行有 5 个可用的 TextBox。当我在第一行的第一个 TextBox 上输入数据,然后按 Tab 键时,焦点移动到
请给我Java中密码验证的正则表达式代码,它应该由一个大写字符、一个整数、一个后面的符号(@、#、$、%、^、&、+、=)和小字符组成。 我一直在尝试使用不同的独立正则表达式和一个组合的正则表达式。
我想在我的 mean-stack 网页上添加一个 Twitter 的关注按钮。我使用以下代码: https://jsbin.com/herikik/3/edit?html,output 在 Ma
在下添加如下代码后到我在 Tumblr 上的主题 .tail { position:fixed; bottom:0px; right:0px; margin-bottom:434px; margin-
我必须从 Angular 应用程序启动一系列窗口。我希望能够让用户单击主页上的按钮以使该窗口重新成为焦点。通常我会在 javascript 中使用类似以下内容来执行此操作: //Launch the
因此,我想显示一些用 AND 或 OR 连接的规则,并且我想为 AND 或 OR 添加颜色,如红色、绿色等。 Fruit = Apple AND Market = SuperMarket1 那么我应该
我正在开发 Windows 商店应用程序,我正在使用 ListView 控件动态添加数据。这些项目被添加到列表的末尾。 Scrollbar 在添加更多数据时出现。我想用底部的滚动条以编程方式突出显示最
(问题仅在 Ubuntu 中出现。在 Windows 中工作正常。我不知道在其他 Linux 环境中) 我已经使用 ComponentListener 的方法在对话框中调用 JTextField 中的
如何将焦点放在时间选择器元素上?我正在开发电视应用程序,因此需要远程操作。所以我需要关注每个元素。TimePicker 有 3 个元素 - 小时列、分钟列和 AM/PM 列。 那么我如何才能专注于这
我是一名优秀的程序员,十分优秀!