首页 文章

准备segue延迟 . 信息滞后但正在呈现

提问于
浏览
0

我正在将otherUserUid和otherUserFullName推送到另一个视图控制器,但它没有被立即调用 . 信息滞后,需要2次点击才能显示信息 .

我认为preparForSegue:在didSelectRowAtIndexPath之前被调用:任何解决方案如何解决这个问题?

干杯!

override func tableView(tableView:UITableView,didSelectRowAtIndexPath indexPath:NSIndexPath){

self.performSegueWithIdentifier("jsqDirectory", sender: self)
    let indexPath = tableView.indexPathForSelectedRow!

    let currentCell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell

    self.otherUserFullName = (currentCell.textLabel?.text)!
    print(self.otherUserFullName)

    self.otherUserUid = (currentCell.detailTextLabel?.text)!
    print(self.otherUserUid)

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "jsqDirectory" {
        if let viewController = segue.destinationViewController as? JSQViewController{

            viewController.senderDisplayName = self.fullName
            viewController.senderId = self.firebase.authData.uid

            viewController.otherUid = self.otherUserUid
            viewController.otherUser = self.otherUserFullName
        }
    }
}

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

    let cell = tableView.dequeueReusableCellWithIdentifier("directoryCell") as UITableViewCell!
    let directoryItem = items[indexPath.row]

    cell.textLabel?.text = directoryItem.fullName
    cell.detailTextLabel!.text = directoryItem.key
    cell.detailTextLabel!.hidden = true

    return cell
}

1 回答

  • 0

    在didSelectRowAtIndexPath中你必须在函数结束时执行segue,就像这样..

    let indexPath = tableView.indexPathForSelectedRow!
    
    let currentCell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell
    
    self.otherUserFullName = (currentCell.textLabel?.text)!
    print(self.otherUserFullName)
    
    self.otherUserUid = (currentCell.detailTextLabel?.text)!
    print(self.otherUserUid)
    self.performSegueWithIdentifier("jsqDirectory", sender: self)
    

相关问题