Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
swift uitableview仅显示用户数组的不同值_Swift_Uitableview_Parse Platform - Fatal编程技术网

swift uitableview仅显示用户数组的不同值

swift uitableview仅显示用户数组的不同值,swift,uitableview,parse-platform,Swift,Uitableview,Parse Platform,我正在使用parse开发一个消息应用程序 我想按发件人筛选查询结果,但它会为每条邮件复制发件人 我认为可以在数组中找到相同的值吗?(在本例中为clientsArray) 有什么想法吗 下面是我使用的代码 var clientName = "" var clientsArray:[String] = [String]() override func viewDidLoad() { super.viewDidLoad() //Message List Query let

我正在使用parse开发一个消息应用程序

我想按发件人筛选查询结果,但它会为每条邮件复制发件人

我认为可以在数组中找到相同的值吗?(在本例中为clientsArray)

有什么想法吗

下面是我使用的代码

var clientName = ""
var clientsArray:[String] = [String]()

override func viewDidLoad() {
    super.viewDidLoad()

    //Message List Query
    let messages = PFQuery(className:"Message")
    messages.whereKey("user", equalTo:PFUser.currentUser()!["retailer"]!)

    messages.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil {

            print("Successfully retrieved \(objects!.count) scores.")

            if let objects = objects as? [PFObject] {

                self.clientName.removeAll()

                for object in objects {

                    if let clientName = object["clientName"] as? String {
                        self.clientsArray.append(clientName)
                    }

                    self.tableView.reloadData()

                    print(self.clientsArray)

                }
            }
        } else {
            print(error)
        }
    }        
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return clientsArray.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("clientsCell", forIndexPath: indexPath)
    let clientName = clientsArray[indexPath.row]

    if let clientNameLabel = cell.viewWithTag(301) as? UILabel {
        clientNameLabel.text = clientName
    }

    return cell
}


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

    if segue.identifier == "showChat" {

        if let destination = segue.destinationViewController as? newChatViewController {

            destination.clientName = clientsArray[(tableView.indexPathForSelectedRow?.row)!]

            //self.hidesBottomBarWhenPushed = true
        }
    }
}

如果不了解数据结构的样子,很难回答这个问题。但是我可以告诉你代码的问题

 if let clientName = object["clientName"] as? String {
     self.clientsArray.append(clientName)
 }
if-let语句只是获取[“clientName”]的对象,它只是您的客户机名称。然后,您将客户名称附加到
clientsArray
对象

这就是你刚刚见到卢克的原因。


我可以帮助解决这个问题,但我需要知道您的数据结构是什么样的。你能打印出整个对象吗?

对不起,丹。我把密码