gpt4 book ai didi

ios - 刷新后 UITableView Cell 不会更新(快速)

转载 作者:行者123 更新时间:2023-11-29 01:43:27 25 4
gpt4 key购买 nike

我有一个表格 View ,其中的单元格根据时间隐藏和取消隐藏某些按钮,但是当我在时间更改后刷新表格 View 时,没有任何更新。我必须关闭应用程序(停止后台)并重新打开它才能使更改生效。

这是我的 tableview 代码的编辑版本,仅包含与问题相关的详细信息:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

var cell = self.meTableView.dequeueReusableCellWithIdentifier("New Joined Party Cell", forIndexPath: NSIndexPath()) as! JoinedPartyCell

var relationship = guestRelations[indexPath.row]
var partyId = relationship.valueForKey("partyID") as! String
var partyObject = PFObject(withoutDataWithClassName: "Party", objectId: partyId)
var party:Party?
partyObject.fetchIfNeededInBackgroundWithBlock({ (object, error) -> Void in

party = Party(pfObject: object!)

var currentDate = NSDate()
var todayComponents = userCalendar.components(requestedDateComponents, fromDate: currentDate)

var dateDifference = userCalendar.components(requestedDateComponents, fromDate: currentDate, toDate: party!.partyDate, options: nil)

var monthString = ""
var dayString = ""
var hourString = ""
var minuteString = ""

if dateDifference.month != 0 {
monthString = "\(dateDifference.month)mo "
}
if dateDifference.day != 0 {
dayString = "\(dateDifference.day)d "
}
if dateDifference.hour != 0 {
hourString = "\(dateDifference.hour)hr "
}
if dateDifference.minute != 0 {
minuteString = "\(dateDifference.minute)min"
}

var countDownString = monthString + dayString + hourString + minuteString

if party!.partyDate.earlierDate(self.today) == self.today {

cell.guestListButton.hidden = false

cell.guestListButton.setTitle("\(party!.guestAmount)/\(party!.guestLimit)", forState: UIControlState.Normal)
cell.hereButton.enabled = true
//cell.hereButton.backgroundColor = UIColor(hex: "#FD985A")

cell.flexibilityLabel.hidden = false
cell.uselessGuestLabel.hidden = false

cell.guestStarButton.hidden = true
cell.hereButton.hidden = true

cell.timerView.hidden = false
cell.timerLabel.text = countDownString

cell.buttonCoverView.hidden = true

} else if (party!.partyDate.earlierDate(self.today) == party!.partyDate && dateDifference.day == 0 && dateDifference.hour > -1 && dateDifference.hour <= 0) || party!.partyDate == NSDate() {

cell.guestListButton.hidden = false

cell.guestListButton.setTitle("\(party!.guestAmount)/\(party!.guestLimit)", forState: UIControlState.Normal)
cell.hereButton.enabled = true
//cell.hereButton.backgroundColor = UIColor(hex: "#FD985A")

cell.flexibilityLabel.hidden = false
cell.uselessGuestLabel.hidden = false

cell.guestStarButton.hidden = true
cell.hereButton.hidden = false

cell.timerView.hidden = true

cell.buttonCoverView.hidden = true

} else {

cell.guestListButton.hidden = true
cell.hereButton.hidden = true
cell.guestStarButton.hidden = false

cell.flexibilityLabel.hidden = true
cell.uselessGuestLabel.hidden = true

cell.timerView.hidden = true

cell.buttonCoverView.hidden = true

}

})

cell.delegate = self

return cell

}

这是我的刷新代码:

func refresh(sender:AnyObject) {

self.newGetParties()
self.refreshControl?.endRefreshing()

}

更新:为澄清起见,newGetParties 函数在获取数据后最后执行 self.meTableView.reloadData()。

通常 reloadData 会更新单元格,就像更新 timerLabel 一样,但是当涉及隐藏的某些 View 或按钮时,除非我关闭并重新打开应用程序,否则它不会更改。

最佳答案

您是否尝试在主线程中重新加载数据?

dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.meTableView.reloadData()
})

关于ios - 刷新后 UITableView Cell 不会更新(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32168633/

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