UIButton.setTitle |更改标题时出现巨大延迟

时间:2016-04-21 09:20:52

标签: ios swift uibutton

我有一个UIButton,当我使用«setTitle»方法时,实际更改我的UI中的标题需要1到20秒。

从异步服务器请求调用该操作(成功时)。

最烦人的是我还在按钮上使用了一个«addAction»方法,这个方法正在立即应用。

我的按钮位于TableViewCell中,所以基本上它看起来像:

override func viewDidLoad() {
    super.viewDidLoad()

    boolAlready = false

    findParticipation()
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cellActions = tableView.dequeueReusableCellWithIdentifier(informationsCellArray[indexPath.row], forIndexPath: indexPath) as! eventDetailsActions

    if boolAlready {
        cellActions.btnParticipate.setTitle("Annuler", forState: UIControlState.Normal)
        cellActions.btnParticipate.addTarget(self, action: "deleteParticipation", forControlEvents: .TouchUpInside)

    } else {
        cellActions.btnParticipate.setTitle("...", forState: UIControlState.Normal)

}

func findParticipation() {
    //serverRequest when success :
    boolAlready = true
    print(« ok »)
    self.tableView.reloadData()
}

我真的不明白,一旦我得到«打印(«ok»)»我可以按下按钮,它按预期启动我的目标。但标题仍然是«...»最多20秒,之后也会发生变化。

我试图在主线程中将dispatch_async(dispatch_get_main_queue()) {}放在我的代码周围,但它仍然不起作用。

0 个答案:

没有答案