首页 > 解决方案 > 社交媒体应用 Swift 的参考视图控制器

问题描述

我目前正在尝试克隆 Instagram 进行练习。我已经创建了所有的 tabBar 控制器。我希望我的用户能够通过点击帖子上的用户名来访问另一个用户的帐户。然后用户可以通过点击他们的帖子之一来查看他们的帖子。为此,我是添加新的 ViewController 还是引用相同的 ViewController?因为添加 new 不会创建无限循环。这是一个解释

标签: iosswift

解决方案


在我看来,我会保留一个视图控制器,我将在用户功能中设置它,因为当前用户和 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


推荐阅读