BBSwiftUIKit数据受影响
TangJingQiu opened this issue · comments
TangJingQiu commented
使用的此第三库里的BBTableView,每三个数据就会循坏,进入交互的数据也是每三个的变化
我的赋值方式,直接赋值,没使用model 是这个影响吗?
Silence-GitHub commented
TangJingQiu commented
每三个数据循环,这是@State导致的吗?简单的数据,就不会,将带头像,带名字点赞一系列多内容模型的单元放进去继续刷新数据就出现问题了
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年8月20日(周四) 晚上11:21
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
推测是直接给@State属性赋值,这样会出问题。@State属性应该设置为private,不能外部赋值。需要修改数据、更细页面,用EnvironmentObject
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Silence-GitHub commented
TangJingQiu commented
那么只能使用model模型赋值?
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年8月23日(周日) 上午10:38
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
目前已知@State会有问题,最简单的 @State var n: Int,也会出问题。这与数据简单、复杂无关。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Silence-GitHub commented
BBTableView内部用UITableView实现,Cell是复用的。如果只更新Cell而不更新Model,数据就会错乱。@State就属于只更新Cell,EnvironmentObject属于更新Model。
TangJingQiu commented
我现在就是使用BBSwiftUI来遍历帖子,每个单元就是一个帖子,例如我给第一个帖子点赞,第1条点赞成功,第4、7、11……都会被点赞了。我是直接给属性,给View传的值,没有创建模型什么的,那我现在该如何去修改这个问题呢?
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年8月27日(周四) 凌晨3:36
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
BBTableView内部用UITableView实现,Cell是复用的。如果只更新Cell而不更新Model,数据就会错乱。@State就属于只更新Cell,EnvironmentObject属于更新Model。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
TangJingQiu commented
我使用BBSwiftUI来刷新遍历帖子数据,每个单元就是一条帖子,我现在给第一条帖子点赞,第4、7、11……条都会变为点赞状态,是的,出现了数据错乱。我是直接给属性赋值,给View赋值的,并没有使用model进行传值,目前就只有这个点赞bug,(之前还有一些数据重复现象,修改了一些属性要求就是@State这些就没了)
那么现在我该如何操作修复这个点赞的bug呢?
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年8月27日(周四) 凌晨3:36
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
BBTableView内部用UITableView实现,Cell是复用的。如果只更新Cell而不更新Model,数据就会错乱。@State就属于只更新Cell,EnvironmentObject属于更新Model。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Silence-GitHub commented
用EnvironmentObject。点赞之后,修改EnvironmentObject里的数据。
TangJingQiu commented
使用你说的这个环境对象,一点就全点赞了,绝望啊
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年8月29日(周六) 中午12:38
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
用EnvironmentObject。点赞之后,修改EnvironmentObject里的数据。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
TangJingQiu commented
EnvironmentObject这个里面只定义两个属性
我定义了一个bool类型去存是否点赞,
我又定义了一个int类型存点赞数
当我点赞时,全部列表里的数据都点赞了
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年8月29日(周六) 中午12:38
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
用EnvironmentObject。点赞之后,修改EnvironmentObject里的数据。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
TangJingQiu commented
大佬,请回复一下🥺
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年8月29日(周六) 中午12:38
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
用EnvironmentObject。点赞之后,修改EnvironmentObject里的数据。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Silence-GitHub commented
EnvironmentObject应该定义一个数组,数组里的元素就是帖子的数据(包括是否点赞、点赞数)。BBTableView用数组初始化。点赞的时候,只更新数组里一个元素的属性(Bool是否点赞,Int点赞数)。建议看一看SwiftUI官方教程 https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
TangJingQiu commented
帖子的一些其他属性要不要放进去这个数组,就是一些用户头像,用户名,帖子标题,等等
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年9月1日(周二) 凌晨1:24
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
EnvironmentObject应该定义一个数组,数组里的元素就是帖子的数据(包括是否点赞、点赞数)。BBTableView用数组初始化。点赞的时候,只更新数组里一个元素的属性(Bool是否点赞,Int点赞数)。建议看一看SwiftUI官方教程 https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Silence-GitHub commented
全都放。数组的一个元素就是一个帖子的数据
TangJingQiu commented
我的数据是通过网络请求过来的,所以在请求的时候就要存放进EnvironmentObject
里吗?然后发生改变又修改EnvironmentObject里的值吗?
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年9月1日(周二) 上午8:48
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
全都放。数组的一个元素就是一个帖子的数据
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Silence-GitHub commented
对
TangJingQiu commented
大佬,那我看看🧐
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年9月1日(周二) 上午10:53
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
对
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
TangJingQiu commented
使用了model,且使用环境变量对象遍历,每条数据的用户名和一些内容是不吃饭的,但是我使用AVplayer播放视频装每个模型里的视频路径值,显示出来的效果是出现了循环,循环的个数根据每个单元的大小除以屏幕 单元越大就会出现2到3个就循环,少就会5-6个才循环
…---原始邮件---
发件人: "Silence-GitHub"<notifications@github.com>
发送时间: 2020年9月1日(周二) 凌晨1:24
收件人: "Silence-GitHub/BBSwiftUIKit"<BBSwiftUIKit@noreply.github.com>;
抄送: "Author"<author@noreply.github.com>;"TangJingQiu"<1993443920@qq.com>;
主题: Re: [Silence-GitHub/BBSwiftUIKit] BBSwiftUIKit数据受影响 (#1)
EnvironmentObject应该定义一个数组,数组里的元素就是帖子的数据(包括是否点赞、点赞数)。BBTableView用数组初始化。点赞的时候,只更新数组里一个元素的属性(Bool是否点赞,Int点赞数)。建议看一看SwiftUI官方教程 https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.