swift - 函数队列 - Swift

标签 swift uitableview segue

我有一个表格,其中每个单元格都有用户的个人资料名称。我希望当单击个人资料名称时,它将转到用户的个人资料页面。我为此从单元创建了一个代表。但问题是,变量“goToProfileVar”在起点处为空。然后我使用“goToCell103”函数为其分配一个值。然后应该在“prepareforsegue”中使用分配的值将用户名数据传递到个人资料页面。问题是,prepareforseque 函数首先起作用,“goToProfileVar”变为空并传递,然后从 cell.username.text 分配变量。

如何对这些函数进行排队?

 var goToProfileVar = String()
 var goToProfileVar2 = String()

func goToCell103(cell: mainCell)
{
    var goToCell103:mainCell? = cell as mainCell
    var indexPath: NSIndexPath  = self.resultsTable.indexPathForCell(goToCell103!)!

    goToProfileVar = cell.usernameLbl.text!
    goToProfileVar2 = cell.objectid.text!
           println("\(goToProfileVar) first.")
    println("\(goToProfileVar2) first.")



}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {



    if (segue.identifier == "goToProfile8") {
        var svc = segue.destinationViewController as! generalProfileLast;
        svc.dataPassed = goToProfileVar}

   else if (segue.identifier == "goToLikers1") {
        var svc = segue.destinationViewController as! likers;
        svc.dataPassed = goToProfileVar2}

    else if (segue.identifier == "goToComments1") {
        var svc = segue.destinationViewController as! enterCommentVC;
        svc.dataPassed = goToProfileVar2}

    else if (segue.identifier == "goToComments2") {
        var svc = segue.destinationViewController as! commenters;
        svc.dataPassed = goToProfileVar2}

      println("\(goToProfileVar) second.")
     println("\(goToProfileVar2) second.")

}

最佳答案

使用当前 View 状态作为模型通常是不好的方法。您的 UI 可能是从某个地方填充的,因此请使用相同的数据源在prepareForSegue 中初始化您的 Controller 。

如果您不想改变很多架构并且仍然喜欢自己的方式,您可以在prepareForSegue中使用goToCell103,并将发送者作为输入参数。在单元中,发送者将是一个录音单元。

关于swift - 函数队列 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31044722/

相关文章:

swift - 将 CollectionDifference 应用到 NSTableView

ios - 将信息从 UITableViewDataSource 传递回 ViewController

ios - 检测 UILabel 换行符。动态地将项目放入 UITableViewCell

Swift:单击带有segue的按钮时显示UIView

ios - segueForUnwindingToViewController 导致 "Warning: Attempt to present <...> on <...> which is already presenting <...>"

ios - Swift,从字符串中获取变量名

swift - 将 Swift 2.3 转换为 Swift 3.0 - 错误,无法使用类型为'的参数列表调用 'dataTask'

ios - 向 UITableView 添加元素

ios - 在 UITableview 单元格中单击按钮会在搜索时给出错误的结果

ios - 当通过 segue 返回时,选项卡栏会从 viewController 中消失 - swift