ios - 社交媒体应用 Swift 的参考视图控制器
问题描述
我目前正在尝试克隆 Instagram 进行练习。我已经创建了所有的 tabBar 控制器。我希望我的用户能够通过点击帖子上的用户名来访问另一个用户的帐户。然后用户可以通过点击他们的帖子之一来查看他们的帖子。为此,我是添加新的 ViewController 还是引用相同的 ViewController?因为添加 new 不会创建无限循环。
解决方案
在我看来,我会保留一个视图控制器,我将在用户功能中设置它,因为当前用户和 profileViewController 上的其他用户之间的唯一区别是按钮“关注”、“编辑配置文件”和“消息” Instagram 的最新版本。
最新版 instagram 上的当前用户在其页面上只有“编辑个人资料”按钮,非当前用户的其他用户具有“关注”和“消息”等按钮
我会写类似的东西
// if this is the currentUser show editButton and hide followButton
if profileUserEmail == currentUserEmail {
followButton.isHidden = True
editButton.isHidden = False
messageButton.isHidden = True
// else show editButton ,messageButton and hide followButton
}else{
followButton.isHidden = False
editButton.isHidden = True
messageButton.isHidden = False
}
profileUserEmail 是您要查看其个人资料页面的用户的电子邮件
您可以保存当前用户登录时的电子邮件
UserDefaults.standard.set(email, forKey: "email")
然后你将此信息设置为常量
let currentUserEmail = UserDefaults.standard.value(forKey: "email") as? String
推荐阅读
- wordpress - 如何在媒体库中显示与原始图像不同的文件夹中的缩略图?
- c# - 如何在c#中将列表添加到列表中的列表中
- three.js - 在three.js中从场景中删除/添加对象
- reactjs - 如何使用uid从firebase获取数据
- c# - 如何填充一个巨大的二维数组
- android - RemoteServiceException:无法在所有具有 oreo 和 pie 的 OnePlus 设备上提供广播
- excel - 如何修复我的代码中不允许我更新 excel 用户表单中其他列的错误?
- java - 在没有 STOMP 和 SockJs 的 Springboot 中测试 Websocket
- oracle12c - 使用 Jdeveloper 在 Oracle ADF 中制作动画图
- scala - 使用 Scala 使用 Json Play 在 S3 上解析 Json 文件