如何在Swift中立即重新加载我的UITableViewCell?

时间:2015-07-14 05:26:16

标签: swift uitableview

class DropTvViewController: UIViewController  , UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var tableView: UITableView!

    var dataTransfer = DataTransfer()
    var responseString : String = ""
    let storeData = StoreData()
    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.delegate = self
        tableView.dataSource = self

        let pfod = PostForData()
        pfod.forData
            { jsonString in
                self.responseString = jsonString as String
                var dict  =  self.dataTransfer.jsonToArray(self.responseString)!
                if let x: AnyObject = dict.valueForKey("readlist")
                {

                    println( dict.count )
                    println("X + \(x)")
                    for var i = 0 ; i < dict.count-1 ; i+=2
                    {
                        println("i : \(i)")
                        let y: AnyObject = x.objectAtIndex(i)
                        let z: AnyObject? = y.objectForKey("epipic")
                        let title : AnyObject? = y.objectForKey("epititle")
                        let time : AnyObject? = y.objectForKey("droptagcreatetime")
                        let pg : AnyObject? = y.objectForKey("pgname")
                        var imagessss =  UIImage (data : pfod.forPicture())
                        self.storeData.add(title as! String, aFs: pg as! String, aTs: time as! String, ph: imagessss! , field1s: z as! String, field2s: z as! String, field3s: z as! String, field4s: z as! String )
                        // I do reload in here,but it will delay about ten seconds.
                        // I am sure the data is ready to read
                        self.tableView.reloadData()

                    }

                }

        }

    }

1 个答案:

答案 0 :(得分:0)

你可以使用你正在做的self.tableView.reloadData(),但只是在循环的错误部分。把它移到外面,你应该没问题。)

如果您要重新加载特定的表格单元格,请尝试:self.tableView.reloadRowsAtIndexPaths(paths,withRowAnimation:UITableViewRowAnimation.None)

从这里回答:https://stackoverflow.com/a/26709571/4891259