我正在尝试创建一个用户可以发布的社交应用程序。
它有一个包含 2 个部分的 tableView
0: depending posts
1: posts
发布数据如下所示:
id: Int
post: String
uploading: Bool = true
如果用户点击“Write a new post”,就会出现一个新的 View Controller,由 VC 处理帖子上传
当用户发送他的帖子时,它会depending posts立即添加到,然后应用程序会弹出到根 VC,+ 它会启动一个 URL 会话
self.dismiss(animated: true, completion: {
PostFunctions.shared.post(){
// ... code ...
if response == 1 {
// move post from depending to normal
} else {
// set the post’s uploading bool to false
}
// send notification to the main vc to reload its tableView
}
})
此代码将帖子上传到网络。如果网络连接失败,或者我的网站响应不被接受,那么我的应用程序中的帖子会将其uploading值更改为false
之后,tableView 会重新加载一个通知
这样我就知道帖子是否上传失败(它在depending posts并且它的uploadingbool 设置为false)。在这种情况下,我会向用户显示一个按钮以重试“<strong>失败。点击重试。”</p>
如果uploading设置为true,那么我会在单元格中显示一个标签,上面写着“<strong>posting...”</p>
Aaaand 如果帖子被接受,我将其从中删除并将其depending posts添加到正常状态posts
我的问题是,我这样做对吗?
或者你会推荐什么?
目前我正在使用这种方法,它工作正常。
图片:

