忽略选择器视图中的重复记录swift 3

时间:2017-02-14 12:50:25

标签: swift swift3 uipickerview

我正在尝试动态选择器视图,只要我在数据库中获得新输入,它就会显示额外的数据。

此时我正在使用通知和观察员来处理实时更新。此外,我将从字符串数组中删除所有项目,以获得一个最新的记录 - 这不是我想要的。

 override func viewDidLoad() {
        super.viewDidLoad()

        pickerView.delegate = self
        pickerView.dataSource = self
        pickerView.sizeToFit()

        NotificationCenter.default.addObserver(forName: SEARCH_RESULT, object: nil, queue: nil, using: catchNotificationForSearchResult)
    }

func catchNotificationForSearchResult(_notification: Notification) {
        let _resultSearch = _notification.object as! [Class]

        for _result in _resultSearch {
            _stringArray.removeAll()
             _stringArray.append("AAA : \(_result.aaa), BBB \(_result.bbb), CCC : \(_result.ccc)")
            pickerView.reloadAllComponents()
        }
    }

的AppDelegate:

 fun test() {
     let _fetchRequest:NSFetchRequest<Class> = Class.fetchRequest()

        do {
            let _searchResults = try DataBaseController.getContext().fetch(_fetchRequest)
            NotificationCenter.default.post(name: SEARCH_RESULT, object: _searchResults)

        } catch {
            print("Error \(error)")
        }

   }

提前致谢!

0 个答案:

没有答案
相关问题