Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBSwiftUIKit数据受影响 #1

Open
TangJingQiu opened this issue Aug 20, 2020 · 18 comments
Open

BBSwiftUIKit数据受影响 #1

TangJingQiu opened this issue Aug 20, 2020 · 18 comments

Comments

@TangJingQiu
Copy link

使用的此第三库里的BBTableView,每三个数据就会循坏,进入交互的数据也是每三个的变化
我的赋值方式,直接赋值,没使用model 是这个影响吗?

@Silence-GitHub
Copy link
Owner

推测是直接给@State属性赋值,这样会出问题。@State属性应该设置为private,不能外部赋值。需要修改数据、更细页面,用EnvironmentObject

@TangJingQiu
Copy link
Author

TangJingQiu commented Aug 22, 2020 via email

@Silence-GitHub
Copy link
Owner

目前已知@State会有问题,最简单的 @State var n: Int,也会出问题。这与数据简单、复杂无关。

@TangJingQiu
Copy link
Author

TangJingQiu commented Aug 26, 2020 via email

@Silence-GitHub
Copy link
Owner

BBTableView内部用UITableView实现,Cell是复用的。如果只更新Cell而不更新Model,数据就会错乱。@State就属于只更新Cell,EnvironmentObject属于更新Model。

@TangJingQiu
Copy link
Author

TangJingQiu commented Aug 29, 2020 via email

@TangJingQiu
Copy link
Author

TangJingQiu commented Aug 29, 2020 via email

@Silence-GitHub
Copy link
Owner

用EnvironmentObject。点赞之后,修改EnvironmentObject里的数据。

@TangJingQiu
Copy link
Author

TangJingQiu commented Aug 29, 2020 via email

@TangJingQiu
Copy link
Author

TangJingQiu commented Aug 29, 2020 via email

@TangJingQiu
Copy link
Author

TangJingQiu commented Aug 31, 2020 via email

@Silence-GitHub
Copy link
Owner

EnvironmentObject应该定义一个数组,数组里的元素就是帖子的数据(包括是否点赞、点赞数)。BBTableView用数组初始化。点赞的时候,只更新数组里一个元素的属性(Bool是否点赞,Int点赞数)。建议看一看SwiftUI官方教程 https://developer.apple.com/tutorials/swiftui/creating-and-combining-views

@TangJingQiu
Copy link
Author

TangJingQiu commented Sep 1, 2020 via email

@Silence-GitHub
Copy link
Owner

全都放。数组的一个元素就是一个帖子的数据

@TangJingQiu
Copy link
Author

TangJingQiu commented Sep 1, 2020 via email

@Silence-GitHub
Copy link
Owner

@TangJingQiu
Copy link
Author

TangJingQiu commented Sep 1, 2020 via email

@TangJingQiu
Copy link
Author

TangJingQiu commented Sep 21, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants