使用Swift删除重复的单元格tableView

时间:2017-05-31 12:54:04

标签: ios swift uitableview

我有以下代码:

import UIKit
import Alamofire

class TestTableViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

    @IBOutlet weak var tableView: UITableView!

    var productsArray = [AnyObject]()

    override func viewDidLoad() {
        super.viewDidLoad()
        Alamofire.request("#######").responseJSON { response in
            let result = response.result
            if let dict = result.value {

                    self.productsArray = dict as! [AnyObject]
                    self.tableView.reloadData()

            }
        }

    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return productsArray.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? BundlesTableViewCell

        let title = productsArray[indexPath.row]["productCode"]
        cell?.titileLabel.text = title as? String
        return cell!
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

,结果显示为附加图片enter image description here

我想在追加单元格之前首先检查productCode,这样如果它一样,它什么都不做

我的json是这样的:

[{"dateCreated":1474391278000,"dateModified":1494504694000,"uuid":"b31366c3-805b-11e6-873b-005056ad572a","retired":false,"description":"SMS 25","name":"SMS 25","status":"ACTIVE","allowMultiple":false,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"SMS","deplete":true,"renew":false,"partyCode":"smsbundle","expiryValue":24,"reminderExpiryValue":0,"productCode":"SMS BUNDLES","walletName":"Go_SMS25","commercialDescription":"25 DAILY SMS"},{"dateCreated":1474391281000,"dateModified":1493129974000,"uuid":"b313753e-805b-11e6-873b-005056ad572a","retired":false,"description":"FACEBOOK 15","name":"FACEBOOK 15","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"facebook","expiryValue":720,"reminderExpiryValue":0,"productCode":"FACEBOOK BUNDLES","walletName":"Monthly_Facebook","commercialDescription":"Monthly Facebook"},{"dateCreated":1474391284000,"dateModified":1494504715000,"uuid":"b313778b-805b-11e6-873b-005056ad572a","retired":false,"description":"TWITTER WEEKLY","name":"TWITTER WEEKLY","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"twitter","expiryValue":168,"reminderExpiryValue":0,"productCode":"TWITTER BUNDLES","walletName":"Weekly Twitter","commercialDescription":"Weelkly Twitter"},{"dateCreated":1474391290000,"dateModified":1493129967000,"uuid":"b3137979-805b-11e6-873b-005056ad572a","retired":false,"description":"TWITTER MONTHLY","name":"TWITTER MONTHLY","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"twitter","expiryValue":720,"reminderExpiryValue":0,"productCode":"TWITTER BUNDLES","walletName":"Monthly_Twitter","commercialDescription":"Monthly Twitter"},{"dateCreated":1474391294000,"dateModified":1494509144000,"uuid":"b3137b4e-805b-11e6-873b-005056ad572a","retired":false,"description":"MEGA 50c","name":"MEGA 50c","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE, SMS, DATA","deplete":false,"renew":true,"partyCode":"hiebundle","expiryValue":24,"reminderExpiryValue":0,"productCode":"MEGA BOOST BUNDLES","walletName":"MEGA 50c","commercialDescription":"USD0.50 MEGA-BOOST BUNDLE"},{"dateCreated":1474391303000,"dateModified":1494406607000,"uuid":"b3137eda-805b-11e6-873b-005056ad572a","retired":false,"description":"DATA BUNDLE 50c","name":"DATA BUNDLE 50c","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.5,"type":"DATA","deplete":true,"renew":false,"partyCode":"zsmart2","expiryValue":720,"reminderExpiryValue":0,"productCode":"DATA BUNDLES","walletName":"Gprs_bundle","commercialDescription":"4.8MB DATA BUNDLE"},{"dateCreated":1474391306000,"dateModified":1494406630000,"uuid":"b3138741-805b-11e6-873b-005056ad572a","retired":false,"description":"DATA BUNDLE USD1","name":"DATA BUNDLE USD1","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":1.0,"type":"DATA","deplete":true,"renew":false,"partyCode":"zsmart2","expiryValue":720,"reminderExpiryValue":0,"productCode":"DATA BUNDLES","walletName":"Gprs_bundle","commercialDescription":"9.5MB DATA BUNDLE"},{"dateCreated":1474391309000,"dateModified":1494406690000,"uuid":"b313f2b0-805b-11e6-873b-005056ad572a","retired":false,"description":"DATA BUNDLE USD3","name":"DATA BUNDLE USD3","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":3.0,"type":"DATA","deplete":true,"renew":false,"partyCode":"zsmart2","expiryValue":720,"reminderExpiryValue":0,"productCode":"DATA BUNDLES","walletName":"Gprs_bundle","commercialDescription":"76MB DATA BUNDLE"},{"dateCreated":1474391313000,"dateModified":1494406700000,"uuid":"b313f533-805b-11e6-873b-005056ad572a","retired":false,"description":"DATA BUNDLE USD5","name":"DATA BUNDLE USD5","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":5.0,"type":"DATA","deplete":true,"renew":false,"partyCode":"zsmart2","expiryValue":720,"reminderExpiryValue":0,"productCode":"DATA BUNDLES","walletName":"Gprs_bundle","commercialDescription":"142.5MB DATA BUNDLE"},{"dateCreated":1474391317000,"dateModified":1494400047000,"uuid":"b313f73e-805b-11e6-873b-005056ad572a","retired":false,"description":"DATA BUNDLE USD10","name":"DATA BUNDLE USD10","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":10.0,"type":"DATA","deplete":true,"renew":false,"partyCode":"zsmart2","expiryValue":720,"reminderExpiryValue":0,"productCode":"DATA BUNDLES","walletName":"Gprs_bundle","commercialDescription":"304MB DATA BUNDLE"},{"dateCreated":1474391320000,"dateModified":1493129857000,"uuid":"b313f938-805b-11e6-873b-005056ad572a","retired":false,"description":"DATA BUNDLE USD20","name":"DATA BUNDLE USD20","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":20.0,"type":"DATA","deplete":true,"renew":false,"partyCode":"zsmart2","expiryValue":720,"reminderExpiryValue":0,"productCode":"DATA BUNDLES","walletName":"Gprs_bundle","commercialDescription":"800MB DATA BUNDLE"},{"dateCreated":1474391324000,"dateModified":1494406791000,"uuid":"b3140331-805b-11e6-873b-005056ad572a","retired":false,"description":"DATA BUNDLE USD45","name":"DATA BUNDLE USD45","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":45.0,"type":"DATA","deplete":true,"renew":false,"partyCode":"zsmart2","expiryValue":720,"reminderExpiryValue":0,"productCode":"DATA BUNDLES","walletName":"Gprs_bundle","commercialDescription":"2000MB DATA BUNDLE"},{"dateCreated":1474391327000,"dateModified":1494406722000,"uuid":"b3140569-805b-11e6-873b-005056ad572a","retired":false,"description":"DATA BUNDLE USD75","name":"DATA BUNDLE USD75","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":75.0,"type":"DATA","deplete":true,"renew":false,"partyCode":"zsmart2","expiryValue":720,"reminderExpiryValue":0,"productCode":"DATA BUNDLES","walletName":"Gprs_bundle","commercialDescription":"4000MB DATA BUNDLE"},{"dateCreated":1474391330000,"dateModified":1493129121000,"uuid":"b3140759-805b-11e6-873b-005056ad572a","retired":false,"description":"10MIN CROSSNET VOICE BUNDLE","name":"10MIN CROSSNET VOICE BUNDLE","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":true,"renew":false,"partyCode":"telecel_go","expiryValue":24,"reminderExpiryValue":0,"productCode":"CROSSNET VOICE BUNDLES","walletName":"Go_SVB1","commercialDescription":"10MINS CROSSNET VOICE BUNDLE"},{"dateCreated":1474391334000,"dateModified":1494509383000,"uuid":"b3140a76-805b-11e6-873b-005056ad572a","retired":false,"description":"MEGA 1","name":"MEGA 1","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE, SMS, DATA","deplete":true,"renew":false,"partyCode":"hiebundle","expiryValue":24,"reminderExpiryValue":24,"productCode":"MEGA BOOST BUNDLES","walletName":"MEGA 1","commercialDescription":"USD1 MEGA-BOOST BUNDLE"},{"dateCreated":1474391337000,"dateModified":1494509412000,"uuid":"b3140dd0-805b-11e6-873b-005056ad572a","retired":false,"description":"MEGA 2","name":"MEGA 2","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE, SMS, DATA","deplete":false,"renew":false,"partyCode":"hiebundle","expiryValue":48,"reminderExpiryValue":0,"productCode":"MEGA BOOST BUNDLES","walletName":"MEGA 2","commercialDescription":"USD2 MEGA-BOOST BUNDLE"},{"dateCreated":1474391340000,"dateModified":1494509486000,"uuid":"b3141030-805b-11e6-873b-005056ad572a","retired":false,"description":"MEGA 5","name":"MEGA 5","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE, SMS, DATA","deplete":true,"renew":false,"partyCode":"hiebundle","expiryValue":720,"reminderExpiryValue":0,"productCode":"MEGA BOOST BUNDLES","walletName":"MEGA 5","commercialDescription":"USD5 MEGA-BOOST BUNDLE"},{"dateCreated":1474391343000,"dateModified":1494509528000,"uuid":"b3141223-805b-11e6-873b-005056ad572a","retired":false,"description":"MEGA 10","name":"MEGA 10","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE, SMS, DATA","deplete":false,"renew":false,"partyCode":"hiebundle","expiryValue":720,"reminderExpiryValue":0,"productCode":"MEGA BOOST BUNDLES","walletName":"MEGA 10","commercialDescription":"USD10 MEGA-BOOST BUNDLE"},{"dateCreated":1474391362000,"dateModified":1493129806000,"uuid":"b3141405-805b-11e6-873b-005056ad572a","retired":false,"description":"20MIN CROSSNET VOICE BUNDLE","name":"20MIN CROSSNET VOICE BUNDLE","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":true,"renew":false,"partyCode":"telecel_go","expiryValue":48,"reminderExpiryValue":0,"productCode":"CROSSNET VOICE BUNDLES","walletName":"Go_SVB2","commercialDescription":"20MINS CROSSNET VOICE BUNDLE"},{"dateCreated":1474391366000,"dateModified":1493129791000,"uuid":"b31415ea-805b-11e6-873b-005056ad572a","retired":false,"description":"50MIN CROSSNET VOICE BUNDLE","name":"50MIN CROSSNET VOICE BUNDLE","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":true,"renew":false,"partyCode":"telecel_go","expiryValue":72,"reminderExpiryValue":0,"productCode":"CROSSNET VOICE BUNDLES","walletName":"Go_SVB5","commercialDescription":"50MINS CROSSNET VOICE BUNDLE"},{"dateCreated":1474391376000,"dateModified":1493129143000,"uuid":"b31417cf-805b-11e6-873b-005056ad572a","retired":false,"description":"INTERNATIONAL VOICE 4 MINS","name":"INTERNATIONAL VOICE 4 MINS","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":false,"renew":false,"partyCode":"Int_vbundles","expiryValue":24,"reminderExpiryValue":0,"productCode":"INTERNATIONAL VOICE BUNDLES","walletName":"International_voice","commercialDescription":"4 MINS INTERNATIONAL VOICE BUNDLE"},{"dateCreated":1474391379000,"dateModified":1493129766000,"uuid":"b31419af-805b-11e6-873b-005056ad572a","retired":false,"description":"INTERNATIONAL VOICE 8 MINS","name":"INTERNATIONAL VOICE 8 MINS","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":false,"renew":false,"partyCode":"Int_vbundles","expiryValue":72,"reminderExpiryValue":0,"productCode":"INTERNATIONAL VOICE BUNDLES","walletName":"Int_Voice2","commercialDescription":"8 MINS INTERNATIONAL VOICE BUNDLE"},{"dateCreated":1474391381000,"dateModified":1493129756000,"uuid":"b3141b8f-805b-11e6-873b-005056ad572a","retired":false,"description":"INTERNATIONAL VOICE 20 MINS","name":"INTERNATIONAL VOICE 20 MINS","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":false,"renew":false,"partyCode":"Int_vbundles","expiryValue":168,"reminderExpiryValue":0,"productCode":"INTERNATIONAL VOICE BUNDLES","walletName":"Int_Voice5","commercialDescription":"20 MINS INTERNATIONAL VOICE BUNDLE"},{"dateCreated":1474391385000,"dateModified":1493129748000,"uuid":"b3141d2c-805b-11e6-873b-005056ad572a","retired":false,"description":"INTERNATIONAL VOICE 40 MINS","name":"INTERNATIONAL VOICE 40 MINS","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":false,"renew":false,"partyCode":"Int_vbundles","expiryValue":240,"reminderExpiryValue":0,"productCode":"INTERNATIONAL VOICE BUNDLES","walletName":"Int_Voice10","commercialDescription":"40 MINS INTERNATIONAL VOICE BUNDLE"},{"dateCreated":1474391389000,"dateModified":1493129739000,"uuid":"b3141ec0-805b-11e6-873b-005056ad572a","retired":false,"description":"INTERNATIONAL VOICE 80 MINS","name":"INTERNATIONAL VOICE 80 MINS","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":false,"renew":false,"partyCode":"Int_vbundles","expiryValue":360,"reminderExpiryValue":0,"productCode":"INTERNATIONAL VOICE BUNDLES","walletName":"Int_Voice20","commercialDescription":"80 MINS INTERNATIONAL VOICE BUNDLE"},{"dateCreated":1474391392000,"dateModified":1493129725000,"uuid":"b3142052-805b-11e6-873b-005056ad572a","retired":false,"description":"NIGHT DATA USD1","name":"NIGHT DATA USD1","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"NiteDataBndle","expiryValue":48,"reminderExpiryValue":0,"productCode":"NIGHT DATA BUNDLES","walletName":"Gprs_night1","commercialDescription":"350MB NIGHT DATA"},{"dateCreated":1474391398000,"dateModified":1493129709000,"uuid":"b31421eb-805b-11e6-873b-005056ad572a","retired":false,"description":"NIGHT DATA USD2","name":"NIGHT DATA USD2","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"NiteDataBndle","expiryValue":120,"reminderExpiryValue":0,"productCode":"NIGHT DATA BUNDLES","walletName":"Gprs_night2","commercialDescription":"800MB NIGHT DATA"},{"dateCreated":1474391401000,"dateModified":1493129655000,"uuid":"b31424e8-805b-11e6-873b-005056ad572a","retired":false,"description":"NIGHT DATA USD3","name":"NIGHT DATA USD3","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"NiteDataBndle","expiryValue":168,"reminderExpiryValue":0,"productCode":"NIGHT DATA BUNDLES","walletName":"Gprs_night3","commercialDescription":"1024MB NIGHT DATA"},{"dateCreated":1474391406000,"dateModified":1493129640000,"uuid":"b3142694-805b-11e6-873b-005056ad572a","retired":false,"description":"DAY DATA USD1","name":"DAY DATA USD1","status":"ACTIVE","allowMultiple":false,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"Daily_dbndle","expiryValue":24,"reminderExpiryValue":0,"productCode":"DAY DATA BUNDLES","walletName":"Daily_Data1","commercialDescription":"300MB DAILY DATA BUNDLE"},{"dateCreated":1474391410000,"dateModified":1493129633000,"uuid":"b314282d-805b-11e6-873b-005056ad572a","retired":false,"description":"DAY DATA USD2","name":"DAY DATA USD2","status":"ACTIVE","allowMultiple":false,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":true,"renew":false,"partyCode":"Daily_dbndle","expiryValue":24,"reminderExpiryValue":0,"productCode":"DAY DATA BUNDLES","walletName":"Daily_Data2","commercialDescription":"1000MB DAILY DATA BUNDLE"},{"dateCreated":1475756166000,"dateModified":1493129533000,"uuid":"bdd958f3-6351-401e-a2e6-e59fd77bea3e","retired":false,"description":"KENAKO WEEKLY","name":"KENAKO WEEKLY","status":"ACTIVE","allowMultiple":false,"renewable":false,"allowPrepaid":true,"allowPostPaid":true,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"doubledata","expiryValue":7,"reminderExpiryValue":0,"productCode":"KENAKO BUNDLES","walletName":"Kenako_Weekly","commercialDescription":"KENAKO WEEKLY"},{"dateCreated":1475756256000,"dateModified":1493129526000,"uuid":"b268d2d4-f445-4262-9c98-6a8832adb5a4","retired":false,"description":"KENAKO MONTHLY","name":"KENAKO MONTHLY","status":"ACTIVE","allowMultiple":false,"renewable":false,"allowPrepaid":true,"allowPostPaid":true,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"doubledata","expiryValue":30,"reminderExpiryValue":0,"productCode":"KENAKO BUNDLES","walletName":"Kenako_Monthly","commercialDescription":"KENAKO MONTHLY"},{"dateCreated":1491299602000,"dateModified":1493129516000,"uuid":"1bdcb54c-70f6-40dc-90f0-dd80bb013f32","retired":false,"description":"100MIN CROSSNET VOICE BUNDLE","name":"100MIN CROSSNET VOICE BUNDLE","status":"ACTIVE","allowMultiple":true,"renewable":false,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"VOICE","deplete":true,"renew":false,"partyCode":"telecel_go","expiryValue":720,"reminderExpiryValue":0,"productCode":"CROSSNET VOICE BUNDLES","walletName":"Go_SVB10","commercialDescription":"100MINS CROSSNET VOICE BUNDLE"},{"dateCreated":1474391422000,"dateModified":1493129501000,"uuid":"b3142cc2-805b-11e6-873b-005056ad572a","retired":false,"description":"USD0.50 for 125","name":"SMS 50","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"SMS","deplete":true,"renew":false,"partyCode":"smsbundle","expiryValue":168,"reminderExpiryValue":0,"productCode":"SMS BUNDLES","walletName":"Go_SMS50","commercialDescription":"125 WEEKLY SMS"},{"dateCreated":1474391425000,"dateModified":1493129492000,"uuid":"b3142e74-805b-11e6-873b-005056ad572a","retired":false,"description":"USD1.50 for 450","name":"SMS 150","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"SMS","deplete":true,"renew":false,"partyCode":"smsbundle","expiryValue":720,"reminderExpiryValue":0,"productCode":"SMS BUNDLES","walletName":"Go_SMS150","commercialDescription":"450 MONTHLY SMS"},{"dateCreated":1474391430000,"dateModified":1493129482000,"uuid":"b3142ffd-805b-11e6-873b-005056ad572a","retired":false,"description":"USD3.00 for 1000 SMS","name":"SMS 300","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"SMS","deplete":true,"renew":false,"partyCode":"smsbundle","expiryValue":720,"reminderExpiryValue":0,"productCode":"SMS BUNDLES","walletName":"Go_SMS300","commercialDescription":"1000 MONTHLY SMS"},{"dateCreated":1474391435000,"dateModified":1494509666000,"uuid":"b3143187-805b-11e6-873b-005056ad572a","retired":false,"description":"Whatsapp Daily - USD0.35","name":"Whatsapp_Daily","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"whatsapp","expiryValue":24,"reminderExpiryValue":0,"productCode":"WHATSAPP BUNDLES","walletName":"Whatsapp_Daily","commercialDescription":"Daily Whatsapp"},{"dateCreated":1474391439000,"dateModified":1493129474000,"uuid":"b314330e-805b-11e6-873b-005056ad572a","retired":false,"description":"Whatsapp Weekly - USD1.00","name":"Weekly Whatsapp","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"whatsapp","expiryValue":168,"reminderExpiryValue":0,"productCode":"WHATSAPP BUNDLES","walletName":"Weekly Whatsapp","commercialDescription":"Weekly Whatsapp"},{"dateCreated":1474391444000,"dateModified":1493129195000,"uuid":"b314348f-805b-11e6-873b-005056ad572a","retired":false,"description":"Whatsapp Monthly - USD2.85","name":"Monthly Whatsapp","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"whatsapp","expiryValue":720,"reminderExpiryValue":0,"productCode":"WHATSAPP BUNDLES","walletName":"Monthly Whatsapp","commercialDescription":"Monthly Whatsapp"},{"dateCreated":1474391447000,"dateModified":1493129185000,"uuid":"b3143616-805b-11e6-873b-005056ad572a","retired":false,"description":"Facebook Daily","name":"FACEBOOK 5","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"facebook","expiryValue":24,"reminderExpiryValue":0,"productCode":"FACEBOOK BUNDLES","walletName":"Facebook_Daily","commercialDescription":"Daily Facebook"},{"dateCreated":1474391451000,"dateModified":1493129176000,"uuid":"b314379e-805b-11e6-873b-005056ad572a","retired":false,"description":"Weekly Facebook - USD1.00","name":"FACEBOOK 10","status":"ACTIVE","allowMultiple":false,"renewable":true,"allowPrepaid":true,"allowPostPaid":false,"amount":0.01,"type":"DATA","deplete":false,"renew":false,"partyCode":"facebook","expiryValue":168,"reminderExpiryValue":0,"productCode":"FACEBOOK BUNDLES","walletName":"Facebook_Weekly","commercialDescription":"Weekly Facebook"}]

所以我想选择productCode。 json有很多产品,但大多数都有相同的产品代码,所以我想选择产品代码而不重新挑选我之前选择的产品

2 个答案:

答案 0 :(得分:2)

在重新加载self.productsArray之前,您需要从tableView删除重复的元素。

要删除重复元素,请参阅:https://stackoverflow.com/a/25739498/5716829

答案 1 :(得分:0)

您不需要删除重复的单元格。从数组中删除重复的对象。请找参考: remove duplicate elements