每次我重新加載我的行並向上滾動時,我都會收到奇怪的加速運動。如果向下滾動,這很好,但滾動備份會導致可怕的抖動效果,導致該應用無用。重新加載表格視圖後的加料運動
我附上的不僅是cellforrowatindex路徑的代碼,還有按鈕。爲行
細胞:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TableViewCell
cell.nopebutton.tag = indexPath.row
cell.nicebutton.tag = indexPath.row
cell.killText.text = object.valueForKey("text") as! String
cell.layoutMargins = UIEdgeInsetsZero
cell.killText.numberOfLines = 0
let score = object.valueForKey("count") as! Int
cell.count.text = "\(score)"
if cell.count.text == "\(0)"
{
cell.count.textColor = UIColor.grayColor()
}
if cell.count.text > "\(0)"
{
cell.count.textColor = UIColor(red: 42.0/255, green: 204.0/255, blue: 113.0/255, alpha: 1)
}
if cell.count.text < "\(0)"
{
cell.count.textColor = UIColor(red: 231.0/255, green: 76.0/255, blue: 50.0/255, alpha: 1)
}
if cell.count.text == "\(50)"
{
cell.count.textColor = UIColor(red: 249.0/255, green: 191.0/255, blue: 59.0/255, alpha: 1)
}
if let dict : NSDictionary = NSUserDefaults.standardUserDefaults().objectForKey("userNiceNopeDictionary") as? NSDictionary {
cell.nicebutton.enabled = true
cell.nopebutton.enabled = true
if let nice = dict[object.objectId] as? Bool{
if nice {
cell.nicebutton.enabled = false
}
else {
cell.nopebutton.enabled = false
}
}
}
let dateUpdated = object.createdAt as NSDate
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "h:mm a"
cell.time.text = (NSString(format: "%@", dateFormat.stringFromDate(dateUpdated)) as String) as String
let replycnt = object.objectForKey("replies") as! Int
if cell.count.text == "\(-10)"
{
object.deleteInBackground()
}
return cell
}
按鈕
@IBAction func topButton(sender: AnyObject) {
var button = sender as! UIButton
// var view = button.superview
//
// var otherButton = view?.viewWithTag(102) as! UIButton
// var label = button.superview!.viewWithTag(110) as! UILabel
// otherButton.enabled = true
// button.enabled = false
var rowNumber = button.tag
var mutableDict = NSMutableDictionary()
if let dict = NSUserDefaults.standardUserDefaults().objectForKey("userNiceNopeDictionary") {
mutableDict = dict.mutableCopy() as! NSMutableDictionary
}
let obj = self.objects[rowNumber] as! PFObject
mutableDict.setValue(true, forKey: obj.objectId)
NSUserDefaults.standardUserDefaults().setObject(mutableDict, forKey: "userNiceNopeDictionary")
NSUserDefaults.standardUserDefaults().synchronize()
let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
let object = objectAtIndexPath(hitIndex)
object.incrementKey("count")
//label.text = object.objectForKey("count") as! String
// self.tableView.reloadData()
object.save()
self.tableView.reloadRowsAtIndexPaths([hitIndex!], withRowAnimation: UITableViewRowAnimation.None)
}
@IBAction func bottomButton(sender: AnyObject) {
var button = sender as! UIButton
var rowNumber = button.tag
var mutableDict = NSMutableDictionary()
if let dict = NSUserDefaults.standardUserDefaults().objectForKey("userNiceNopeDictionary") {
mutableDict = dict.mutableCopy() as! NSMutableDictionary
}
let obj = self.objects[rowNumber] as! PFObject
mutableDict.setValue(false, forKey: obj.objectId)
NSUserDefaults.standardUserDefaults().setObject(mutableDict, forKey: "userNiceNopeDictionary")
NSUserDefaults.standardUserDefaults().synchronize()
let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
let object = objectAtIndexPath(hitIndex)
object.incrementKey("count", byAmount: -1)
self.tableView.reloadRowsAtIndexPaths([hitIndex!], withRowAnimation: UITableViewRowAnimation.None)
object.save()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "killDetail"){
let indexPath = self.tableView.indexPathForSelectedRow()
let obj = self.objects[indexPath!.row] as! PFObject
let detailVC = segue.destinationViewController as! DetailViewController
detailVC.kill = obj
}
}
}
我的印象是,有一個在我的高度的問題,所以我已經提供了一個代碼以及下。
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.separatorInset = UIEdgeInsetsZero
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
self.tableView.separatorColor = UIColor(red: 236.0/255, green: 240.0/255, blue: 241.0/255, alpha: 1)
navigationController?.tabBarController?.tabBar.hidden = true
tabBarController?.tabBar.hidden = true
self.tableView.estimatedRowHeight = 60
self.tableView.rowHeight = UITableViewAutomaticDimension
locationManager.desiredAccuracy = 1000
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
我不能爲我的生活弄清楚發生了什麼事情導致這個混蛋。就像我說的,我認爲它可能與行高的自動維度有關,但是當我改變時,問題仍然很明顯。
你不能從你的gif混蛋動作中辨別出來,但是我之前看到過這種情況。說實話,我很驚訝,你沒有看到這種行爲向下滾動。應該發生在兩個方面。無論如何,在我的情況下,每次顯示單元格時我都會進行大量處理。你的問題只是在重寫func tableView。嘗試註釋掉像NSDictionary和dateFormat的代碼,看看它是否有幫助。 –
@SamB這些是我嘗試過的第一件事。在我重建之前,我遺漏了字典和日期格式,但是我仍然遇到了問題。 –
由於我看到你的代碼沒有錯,在這一點上它是一個消除過程的問題。將所有內容從let cell = tableView註釋掉並開始一次添加幾行代碼。另外,請嘗試在實際設備上進行測試。也許你的模擬器或Xcode耗盡內存或空間。對不起,這些是最難調試的問題 –