swift - 仅使用两个 View Controller 循环 - 显示用户关注者的用户配置文件

标签 swift xcode firebase

我真的不知道我应该怎么调用它。我制作了一个应用程序,它有一个选定用户的配置文件 View Controller ,以及一个将重定向到名为 FollowersViewController 的新 View Controller 的按钮。在那里您可以看到用户拥有的所有关注者。

但这就是我想要完成的:

假设您进入用户 A 的个人资料,然后查看用户 A 拥有的关注者。然后你会在 FollowersViewController 中看到用户 A 拥有的所有关注者。但是,当您在 FollowersTableViewController 中单击 User B(因为用户 B 关注用户 A)时,我希望它返回到 ProfileViewController,并显示用户 B 的个人资料。然后我可以进入用户 B 的关注者并单击用户 C,我将被重定向到用户 C 的个人资料。

我只想用两个 ViewController(ProfileViewController 和 FollowersViewController)完成这个循环

有人知道我该怎么做吗?

我已经使用 SearchForOtherUser 中的 prepareForSegue 来显示正确的内容,这是保存 selectedUser 数据的变量:

var selectedUser:[String:Any]=[:]

最佳答案

我认为你可以使用委托(delegate)模式来完成这个场景,在 FollowersViewController 中添加委托(delegate),当你选择一个关注者时,调用这个委托(delegate)方法并返回到 ProfileViewController,然后在 ProfileViewController 中实现委托(delegate)方法来更新用户配置文件。 不要忘记在显示 FollowersViewController 时将委托(delegate)与 ProfileViewController 连接 尝试这样的事情:

class Profile: NSObject {
// profile data
}

protocol FollowersViewDelegate: class {
func didSelectFollower(with profile: Profile)
}

class FollowersViewController: UIViewController {
weak var delegate: FollowersViewDelegate!
}

class ProfileViewController: UIViewController, FollowersViewDelegate {
var profile: Profile!
func didSelectFollower(with profile: Profile) {
    self.profile = profile
    // update profile data here
}
}

关于swift - 仅使用两个 View Controller 循环 - 显示用户关注者的用户配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52782594/

相关文章:

cordova - 如何在 firebase 中处理推送通知

android - 更新 Firestore 文档时出现 Coroutine JobCancellationException

ios - Swift 中 Realm 查询的交叉引用谓词

iOS Swift didSelectRowAtIndexPath 不工作

ruby - 安装——mysql2 gem 在使用 rbenv 和 Ruby 1.8.7 的 OSX Mavericks 上失败

authentication - 没有为第二个选项卡触发 Firebase onauth

ios - Swift 正则表达式匹配 unicode

ios - "Non-portable path to file "File.h "; specified path differs in case from file name on disk"更新到 Xcode 8.3 后桥接头中的警告

ios - 永远不知道要使用哪个个人资料组合进行签名

iphone - 如何更新推送通知的配置文件 - IOS