我真的不知道我应该怎么调用它。我制作了一个应用程序,它有一个选定用户的配置文件 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/