удалить все объекты, кроме одного, при сортировке группы объектов в ячейке таблицы (Swift5) - PullRequest
0 голосов
/ 22 мая 2019

Когда мой код загружает 5 объектов, отображаются в каждой ячейке таблицы.Когда я нажимаю кнопку, она сортирует сущность, но остальные 4 сущности все еще отображаются.Я добавил фото ниже, чтобы показать вам именно то, что я ищу.Когда объект нажат, он сортируется, но отображаются все объекты, и я хочу только 1.

   @objc func l1UPBTN(sender: UIButton){
            let appD = UIApplication.shared.delegate as! AppDelegate

            let context = appD.persistentContainer.viewContext

            let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "Data")
            fetchRequest.sortDescriptors = [NSSortDescriptor(key: "Name", ascending: true)]


            do {
                itemName = try context.fetch(fetchRequest)



                self.theScores.reloadData()
            }catch {
                print("Ashley Tisdale")
            }


}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let title = itemName[indexPath.row]
    let cell = theScores.dequeueReusableCell(withIdentifier: "MyCell", for : indexPath)
    cell.textLabel!.numberOfLines = 2
    cell.selectionStyle = .default
    let attr1 = title.value(forKey: "atBATS") as? String


    let attr3 = title.value(forKey: "age") as? String
    let attr4 = title.value(forKey: "weight") as? String

    let attr2 = title.value(forKey: "hits") as? String
    let attr5 = title.value(forKey: "positon") as? String

    let text = [attr1,"  Weight :",attr3,"\n","Height : ",attr2," Age : ",attr4," Position :",attr5].flatMap { $0 }.reduce("", +)
    cell.textLabel?.text = "\(text)"

    cell.textLabel?.textAlignment = .center

    cell.layoutMargins = UIEdgeInsets.zero



    cell.preservesSuperviewLayoutMargins = false
    cell.separatorInset = UIEdgeInsets.zero
    cell.layoutMargins = UIEdgeInsets.zero


    return cell

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...