2016-04-08 1 views
0

Я подталкиваю otherUserUid и otherUserFullName другому контроллеру представления, но он не является вызовом немедленно. Информация отстает, и для получения информации требуется 2 щелчка.Подготовьтесь к задержке списания. Информация задерживается, но представляется

Я думаю, что prepForSegue: вызывается до didSelectRowAtIndexPath: любые решения, как исправить это?

Cheers!

переопределение функ 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 
} 

ответ

0

в didSelectRowAtIndexPath вы должны выполнить SEGUE в конце функции, как thiss ..

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) 
+0

Спасибо дружище. Это сработало! –

+0

вы выполняли слишком рано, чем передавали значения следующему виду контроллера. обязательно отметьте этот ответ как «Правильно» и «пальцы вверх» –

Смежные вопросы