gpt4 book ai didi

ios - 在 NavBar 上使用 Back 后,RefreshControl 会导致 TableView 的第一个 Cell 出错

转载 作者:可可西里 更新时间:2023-11-01 00:23:06 26 4
gpt4 key购买 nike

我在 NavigationController 中嵌入了一个 TableView(并且嵌入在 TabBar Controller 中)。我在每个单元格中都有一个用户名按钮,可以连接到用户的个人资料。

enter image description here

然而,当我在个人资料页面的导航栏上点击“返回”并返回到 tableview 后,似乎我遇到了一些问题。

enter image description here

enter image description here

如果我再次下拉,它会刷新,但这次,顶行的用户名变得不可点击,而其他行按预期工作。

请注意,我在 tableView 的 viewDidLoad 中调用了 self.theRefreshControl = UIRefreshControl(),但我不确定在使用后它是否被调用返回键。

请注意,我使用 prepareForSegue 执行 segue。


总结

  • 如果我转到通知页面并尝试单击用户名,单击用户名按钮并继续运行

  • 如果我转到通知并拉动刷新,第一行的用户名按钮不起作用

  • 如果我转到通知但不进行任何刷新,用户名按钮会继续并返回(因此不会出现错误)。

  • 如果我转到通知并拉动刷新,refreshControl 图标出现并消失,但现在,它不允许我点击顶行的用户名按钮。

  • 如果我刷新通知,它不会让我点击第一行的用户名。如果我点击第二个单元格中的第二个用户名,它会转到用户的个人资料,但是当我点击后退按钮时,它会出现如下错误:

enter image description here

ViewDidLoad() 中的代码:

 override func viewDidLoad() {
super.viewDidLoad()

self.theRefreshControl = UIRefreshControl()
self.theRefreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.theRefreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(theRefreshControl)
}

func refresh(sender: AnyObject) {
if isFirstLoad == false {
currentPage = 1
getStuff()
}

self.theRefreshControl.endRefreshing()
}

我还尝试在 self.tableView.addSubview(theRefreshControl) 上方和下方添加 self.tableView.backgroundView = refreshControl;还尝试用 self.tableView.backgroundView = refreshControl 替换 self.tableView.addSubview(theRefreshControl) 但不幸的是没有运气

最佳答案

你应该像这样实例化 refreshControl 的方式:

override func viewDidLoad() {
let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: "refresh:", forControlEvents: .ValueChanged)
tableView.backgroundView = refreshControl // <- THIS!!!
}

this answer 中所述.

我猜你的 refreshControl 在你的单元格前面,所以如果上面的方法不起作用试试这个: viewDidLoad 中的 tableView.sendSubviewToBack(theRefreshControl)/p>

编辑:由于 tableView.sendSubviewToBack(theRefreshControl) 是解决方案,请考虑向 Apple 提交错误,因为它应该在您设置 refreshControl 时自动发生 作为 tableView.backgroundView

关于ios - 在 NavBar 上使用 Back 后,RefreshControl 会导致 TableView 的第一个 Cell 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35391236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com