ios – The right way to forestall UITableview cells from repeating the view inside it?

0
11
ios – The right way to forestall UITableview cells from repeating the view inside it?


I’ve a desk view which exhibits an array of signature views with visitor particulars. When the cells are scrolled the signature from cell 1 is repeated in cell 6 and a couple of in cell 7 and so forth. (desk view reusing of cells drawback)

I attempted utilizing the cells Put together to reuse perform and cleared the cells signature view by making it nil and than when the brand new/reused cell is assigned create and assign a brand new signature view. In my different strategy I attempted to clear the array of the signature views which holds the signature paths in reuse perform. and when the cell is created that point primarily based on the index path the cell.signature view is appended inside an array and saved.

so when the person scrolls by default the signature path is made empty (new cells) however when the person reaches to a index path which he beforehand reached and since inside our array we’ve got appended that signature view we fetch and assign the trail to the present signature view however nonetheless the indicators are repeating.

I can present code of what I attempted.


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    let cellReusableId = String(describing: ProfileSignataureTableViewCell.self)
    
    guard let cell = tableView.dequeueReusableCell(withIdentifier: cellReusableId, for: indexPath) as? ProfileSignataureTableViewCell
    else { fatalError("Cell not exists in storyboard") }
    
    cell.firstNameText.delegate = self
    cell.lastNameText.delegate = self
    cell.ageText.delegate = self
    cell.firstNameText.tag = indexPath.row
    cell.lastNameText.tag = indexPath.row
    cell.ageText.tag = indexPath.row
    //   cell.signatureView.tag = indexPath.row
    
     cell.signatureView?.delegate = self
    cell.signatureView?.tag = indexPath.row
    
    
    if let existingSignature = signArray.first(the place: { $0.indexPath == indexPath.row })?.signatureViews {
        // Reuse the prevailing signature view if discovered
        cell.signatureView = existingSignature
        print("Reusing present signature view for row (indexPath.row)")
        
        // use the prevailing signature views array to attract the signature again once more not png knowledge
        if let signatureData = existingSignature.pathArray as? [Any] {
            
            cell.signatureView?.pathArray = signatureData as! NSMutableArray
        }
        
    } else {
        
        
        if let signatureView = cell.signatureView {
            // Save the brand new signature view within the array
            signArray.append(Signatures(indexPath: indexPath.row, signatureViews: signatureView))
            print("Saved new signature view for row (indexPath.row)")
            
            
        } else {
            print("No signature view out there for row (indexPath.row)")
        }
    }
        
    cell.btn_clear.tag = indexPath.row
    cell.btn_clear.addTarget(self, motion: #selector(editButtonPressed), for: .touchUpInside)
   
    
    print("the brand new array rely is (signArray.rely)")
    
    return cell
    
}


struct Signatures {
    
    var indexPath: Int?
    var signatureViews: SamsoSignatureView?
    
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here