Om Sanatan needs to attract extra consideration to this query.
Tableview cells are seen whereas app is in debug however when tried to terminate app and than attempt to reopen the app, cells should not seen.
Method(Which i utilized in my app):
lazy var contactPickerScene: ContactTabelViewController = {
guard let contactPickerScene = self.storyboard?.instantiateViewController(identifier: “ContactTabelViewController”) as? ContactTabelViewController else {
return ContactTabelViewController()
}
return contactPickerScene
}()
contactPickerScene.contactDelegate = self
contactPickerScene.multiSelectEnabled = true
contactPickerScene.subtitleCellValue = .e mail
contactPickerScene.view.body = self.contactListView.bounds
self.addChild(contactPickerScene)
self.contactListView.addSubview(contactPickerScene.view)
contactPickerScene.didMove(toParent: self)
public class ContactTabelViewController: UITableViewController, UISearchResultsUpdating, UISearchBarDelegate {
—————————
public override func viewDidLoad() {
tremendous.viewDidLoad()
// Uncomment the next line to protect choice between displays
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the next line to show an Edit button within the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
self.title = “Contacts”
self.tableView.dataSource = self
self.tableView.delegate = self
inititlizeBarButtons()
initializeSearchBar()
registerContactCell()
fetchContacts()
}
—————————
}
// MARK: – Contact Operations
extension ContactTabelViewController {
func fetchContacts() {
DispatchQueue.international().async {
self.getContacts( {(contacts, error) in
if (error == nil) {
DispatchQueue.predominant.async(execute: {
// self.tableView.dataSource = self
// self.tableView.delegate = self
self.contactsList = contacts
self.tableView.reloadData()
})
}
})
}
}
func getContacts(_ completion: @escaping ContactsHandler) {
if contactsStore == nil {
contactsStore = CNContactStore()
}
let error = NSError(area: “ContactPickerErrorDomain”, code: 1, userInfo: [NSLocalizedDescriptionKey: “No Contacts Access”])
change CNContactStore.authorizationStatus(for: CNEntityType.contacts) {
case CNAuthorizationStatus.denied, CNAuthorizationStatus.restricted:
DispatchQueue.predominant.async {
if self.contactsList.isEmpty {
self.tableView.isScrollEnabled = false
self.resultSearchController.searchBar.isHidden = true
self.tableView.setEmptyMessage(“We couldn’t fetch your contacts. Please permit contacts permission.”)
}
}
case CNAuthorizationStatus.notDetermined:
contactsStore?.requestAccess(for: CNEntityType.contacts, completionHandler: { (granted, error) -> Void in
if (!granted ){
DispatchQueue.predominant.async(execute: { () -> Void in
completion([], error! as NSError?)
})
}
else{
DispatchQueue.international().async {
self.orderedContacts = [String: [CNContact]]()
self.getContacts(completion)
}
}
})
case CNAuthorizationStatus.licensed:
var contactsArray = [CNContact]()
let contactFetchRequest = CNContactFetchRequest(keysToFetch:[CNContactVCardSerialization.descriptorForRequiredKeys()])
contactFetchRequest.sortOrder = CNContactSortOrder.givenName
do {
strive contactsStore?.enumerateContacts(with: contactFetchRequest, usingBlock: { (contact, cease) -> Void in
var key: String = “#”
if let firstLetter = contact.givenName[0..<1] , firstLetter.containsAlphabets() {
key = firstLetter.uppercased()
}
var contacts = [CNContact]()
if let segregatedContact = self.orderedContacts[key] {
contacts = segregatedContact
}
if(contactsArray.depend == 0){
if !Fixed.boolIsSubscribe {
contacts.append(contact)
}
}
contacts.append(contact)
self.orderedContacts[key] = contacts
contactsArray.append(contact)
})
self.sortedContactKeys = Array(self.orderedContacts.keys).sorted(by: <)
if self.sortedContactKeys.first == “#” {
self.sortedContactKeys.removeFirst()
self.sortedContactKeys.append(“#”)
}
completion(contactsArray, nil)
}
//Catching exception as enumerateContactsWithFetchRequest can throw errors
catch let error as NSError {
print(error.localizedDescription)
}
@unknown default:
break
}
}
}
Whereas Debug:
After App Killed:
i need to outcome identical as i bought in debug. cell must load load whereas app working after kill from debug state.
on this subject i already spent 2 days and in addition create separate UItableviewcontroller however getting identical outcome.
XCode Model 15.0
Swift 5.0
iOS 17.0
MacOS Sonoma
i’m utilizing this surroundings at the moment.
Identical subject once more in several state of affairs
i discovered identical subject once more in UITableView in identical challenge and historical past web page exhibiting me some historical past whereas machine connect to system and app is working however at any time when i kill app and run it is exhibiting clean tableview.
Logs whereas linked to machine and run
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 146 ==> GetLoadFileFromDocumentDict()
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 2 ==> 171 ==> tableView(_:numberOfRowsInSection:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 2 ==> 171 ==> tableView(_:numberOfRowsInSection:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 340.0 ==> 262 ==> tableView(_:heightForRowAt:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 75.0 ==> 266 ==> tableView(_:heightForRowAt:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 2 ==> 171 ==> tableView(_:numberOfRowsInSection:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 181 ==> tableView(_:cellForRowAt:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 340.0 ==> 262 ==> tableView(_:heightForRowAt:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 181 ==> tableView(_:cellForRowAt:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 75.0 ==> 266 ==> tableView(_:heightForRowAt:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 340.0 ==> 262 ==> tableView(_:heightForRowAt:)
09:16:36: <SharingApp.HistoryViewController: 0x11a4ac770> ==> 75.0 ==> 266 ==> tableView(_:heightForRowAt:)
Logs whereas not linked to machine and run
09:17:49: <SharingApp.HistoryViewController: 0x119563620> ==> 146 ==> GetLoadFileFromDocumentDict()
09:17:49: <SharingApp.HistoryViewController: 0x119563620> ==> 2 ==> 171 ==> tableView(_:numberOfRowsInSection:)
09:17:49: <SharingApp.HistoryViewController: 0x119563620> ==> 2 ==> 171 ==> tableView(_:numberOfRowsInSection:)
09:17:50: <SharingApp.HistoryViewController: 0x119563620> ==> 340.0 ==> 262 ==> tableView(_:heightForRowAt:)
09:17:50: <SharingApp.HistoryViewController: 0x119563620> ==> 75.0 ==> 266 ==> tableView(_:heightForRowAt:)
09:17:50: <SharingApp.HistoryViewController: 0x119563620> ==> 2 ==> 171 ==> tableView(_:numberOfRowsInSection:)
09:17:50: <SharingApp.HistoryViewController: 0x119563620> ==> 340.0 ==> 262 ==> tableView(_:heightForRowAt:)
09:17:50: <SharingApp.HistoryViewController: 0x119563620> ==> 75.0 ==> 266 ==> tableView(_:heightForRowAt:)
i do not know why cellForRowAt just isn’t getting referred to as.
HistoryViewcontroller.Swift
import UIKit
import Images
import QuickLook
import Kingfisher
import GoogleMobileAds
struct Historical past : Codable {
let identify: String?
let information: Knowledge?
let date: Date?
let measurement: Int?
let docType: URLType
}
class HistoryViewController: UIViewController {
@IBOutlet weak var tblHistory: UITableView!
var rightBarButton : UIBarButtonItem!
var arraySplitArray = [URL]()
lazy var previewItem = NSURL()
var arryValue = [URL]()
var imageLocal = [UIImage]()
var selectedIndexPath = [IndexPath]()
var boolIsNativeAdHide : Bool = false
enum Errors : Error {
case error1(str: String?)
case error2
case error3
}
override func viewDidLoad() {
tremendous.viewDidLoad()
rightBarButton = UIBarButtonItem(title: “Delete All”, type: .plain, goal: self, motion: #selector(didTapSelectButton(sender:)))
navigationItem.rightBarButtonItem = rightBarButton
isSmallNativeAd = false
tblHistory.register(UINib(nibName: “HistoryTableViewCell2”, bundle: nil), forCellReuseIdentifier: “HistoryTableViewCell2”)
tblHistory.register(UINib(nibName: “NativeAdCell”, bundle: nil), forCellReuseIdentifier: “NativeAdCell”)
tblHistory.dataSource = self
tblHistory.delegate = self
self.GetLoadFileFromDocumentDict()
}
override func viewDidAppear(_ animated: Bool) {
tremendous.viewDidAppear(animated)
}
override func viewWillAppear(_ animated: Bool) {
tremendous.viewWillAppear(animated)
self.title = “Historical past”
}
@objc
func didTapSelectButton(sender: AnyObject){
let refreshAlert = UIAlertController(title: “Affirmation”, message: “Are you positive you need to delete historical past?”, preferredStyle: UIAlertController.Fashion.alert)
refreshAlert.addAction(UIAlertAction(title: “Sure”, type: .default, handler: { (motion: UIAlertAction!) in
self.CleanHistory()
}))
refreshAlert.addAction(UIAlertAction(title: “No”, type: .cancel, handler: { (motion: UIAlertAction!) in
print(“Deal with Cancel Logic right here”)
}))
current(refreshAlert, animated: true, completion: nil)
}
func CleanHistory(){
let fileManager = FileManager.default
let myDocuments = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
let folderURL = myDocuments.appendingPathComponent(Fixed.strFolderName)
guard let filePaths = strive? fileManager.contentsOfDirectory(at: folderURL, includingPropertiesForKeys: nil, choices: []) else { return }
for filePath in filePaths {
strive? fileManager.removeItem(at: filePath)
}
DispatchQueue.predominant.asyncAfter(deadline: .now() + 1){
// create the alert
let alert = UIAlertController(title: “Info”, message: “Historical past Deleted Efficiently.”, preferredStyle: UIAlertController.Fashion.alert)
// add an motion (button)
alert.addAction(UIAlertAction(title: “OK”, type: UIAlertAction.Fashion.default, handler: nil))
// present the alert
self.current(alert, animated: true, completion: nil)
}
self.GetLoadFileFromDocumentDict()
}
func GetLoadFileFromDocumentDict() {
self.arraySplitArray.removeAll()
self.arryValue.removeAll()
if let arrUrls = FileManager.allRecordedData() {
arryValue = arrUrls.filter({ url in
if url.lastPathComponent.accommodates(“png”) ||
url.lastPathComponent.accommodates(“jpg”) ||
url.lastPathComponent.accommodates(“gif”) ||
url.lastPathComponent.accommodates(“tif”) ||
url.lastPathComponent.accommodates(“JPG”) ||
url.lastPathComponent.accommodates(“PNG”) ||
url.lastPathComponent.accommodates(“HEIC”) ||
url.lastPathComponent.accommodates(“WEBM”) ||
url.lastPathComponent.accommodates(“MPG”) ||
url.lastPathComponent.accommodates(“MPEG”) ||
url.lastPathComponent.accommodates(“MPE”) ||
url.lastPathComponent.accommodates(“MP4”) ||
url.lastPathComponent.accommodates(“M4P”) ||
url.lastPathComponent.accommodates(“M4V”) ||
url.lastPathComponent.accommodates(“AVI”) ||
url.lastPathComponent.accommodates(“WMV”) ||
url.lastPathComponent.accommodates(“MOV”) ||
url.lastPathComponent.accommodates(“pdf”) ||
url.lastPathComponent.accommodates(“vcf”) ||
url.lastPathComponent.accommodates(“m4a”) {
return true
}else {
return false
}
})
for fileURL in arryValue {
if(fileURL.pathExtension != “”){
arraySplitArray.append(fileURL)
}
}
if arraySplitArray.depend > 0 {
if !Fixed.boolIsSubscribe {
arraySplitArray.insert(URL(string: “AD”)!, at: 0)
}
rightBarButton.isEnabled = true
}else{
rightBarButton.isEnabled = false
}
RBLogger.log(“(self) ==> (#line) ==> (#perform)”)
self.tblHistory.reloadData()
}
}
func deleteData(at indexPath: IndexPath) {
print(indexPath.row)
RemoveFileFromDocumentDictionary(indexPath: indexPath)
}
func RemoveFileFromDocumentDictionary(indexPath : IndexPath) {
let fileManager = FileManager.default
do {
strive fileManager.removeItem(at:arraySplitArray[indexPath.row])
arraySplitArray.take away(at: indexPath.row)
self.tblHistory.reloadData()
} catch {
print(error)
}
}
}
//MARK:- Tableview Strategies
extension HistoryViewController : UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
RBLogger.log(“(self) ==> (arraySplitArray.depend) ==> (#line) ==> (#perform)”)
if arraySplitArray.isEmpty {
tblHistory.setEmptyView(picture: UIImage(named: “noData”)!, title: “”, message: “”)
}else {
tblHistory.restoreView()
}
return arraySplitArray.depend
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
RBLogger.log(“(self) ==> (#line) ==> (#perform)”)
let url = arraySplitArray[indexPath.row]
if url.absoluteString == “AD” {
let nativeAdCell = tableView.dequeueReusableCell(withIdentifier: “NativeAdCell”) as! NativeAdCell
if !boolIsNativeAdHide {
loadNativeAd(view: nativeAdCell.adView, isSmallNativeAd: isSmallNativeAd) {[weak self] isLoad in
DispatchQueue.predominant.async {
if !isLoad {
self?.boolIsNativeAdHide = true
self?.tblHistory.reloadRows(at: [IndexPath(row: indexPath.row, section: indexPath.section)], with: .none)
}else {
print(“Advert already load.”)
}
}
}
}
nativeAdCell.selectionStyle = .none
return nativeAdCell
}else {
guard let cell : HistoryTableViewCell2 = tableView.dequeueReusableCell(withIdentifier: “HistoryTableViewCell2”) as? HistoryTableViewCell2 else {
return UITableViewCell()
}
do {
let checkVideoOrImage = self.checkURLType(inputURL: arraySplitArray[indexPath.row])
if checkVideoOrImage == “Picture” {
let information = strive Knowledge(contentsOf: self.arraySplitArray[indexPath.row])
DispatchQueue.predominant.async {
cell.imgThumb.picture = UIImage(information: information)
}
}else if checkVideoOrImage == “Video”{
cell.imgThumb.picture = self.generateThumbnail(path: arraySplitArray[indexPath.row])
}else if (arraySplitArray[indexPath.row].pathExtension.lowercased() == “pdf”){
cell.imgThumb.picture = UIImage.init(named: “pdf”)
}else if (arraySplitArray[indexPath.row].pathExtension.lowercased() == “vcf”){
cell.imgThumb.picture = UIImage.init(named: “vcf”)
}else if (arraySplitArray[indexPath.row].pathExtension.lowercased() == “m4a”){
cell.imgThumb.picture = UIImage.init(named: “musical”)
}else {
cell.imgThumb.picture = UIImage.init(named: “doc”)
}
cell.lblName.textual content = arraySplitArray[indexPath.row].lastPathComponent
let resourceValues = strive arraySplitArray[indexPath.row].resourceValues(forKeys: [.fileSizeKey])
let fileSize = resourceValues.fileSize!
cell.lblSize.textual content = ByteCountFormatter().string(fromByteCount: Int64(fileSize))
} catch { print(error) }
let attributes = strive? FileManager.default.attributesOfItem(atPath: arraySplitArray[indexPath.row].path)
if let date = attributes?[.modificationDate] {
print(“File Modification date is %@”, date)
let dateFormatter = DateFormatter()
let tempLocale = dateFormatter.locale
dateFormatter.locale = Locale(identifier: “en_US_POSIX”)
dateFormatter.dateFormat = “yyyy-MM-dd’T’HH:mm:ssZ”
dateFormatter.dateFormat = “dd-MM-yyyy”
dateFormatter.locale = tempLocale
let dateString = dateFormatter.string(from: date as! Date)
cell.lblDate.textual content = dateString
}
cell.btnViewClick = {(_ aCell: HistoryTableViewCell2) -> Void in
DispatchQueue.predominant.async {
self.previewItem = self.arraySplitArray[indexPath.row] as NSURL
let quickLookController = QLPreviewController()
quickLookController.dataSource = self
self.current(quickLookController, animated: true, completion: nil)
}
}
cell.selectionStyle = .none
return cell
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let url = arraySplitArray[indexPath.row]
if url.absoluteString == “AD” {
if boolIsNativeAdHide {
RBLogger.log(“(self) ==> 0.0 ==> (#line) ==> (#perform)”)
return 0.0
}else{
RBLogger.log(“(self) ==> (nativeAdHeight() + 40.0) ==> (#line) ==> (#perform)”)
return nativeAdHeight() + 40.0
}
}else {
RBLogger.log(“(self) ==> 75.0 ==> (#line) ==> (#perform)”)
return 75.0
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let url = arraySplitArray[indexPath.row]
if url.absoluteString == “AD” {
return
}
if(tblHistory.isEditing){
selectedIndexPath.append(indexPath)
print(indexPath.row)
}
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let url = arraySplitArray[indexPath.row]
if url.absoluteString == “AD” {
return
}
if(tblHistory.isEditing){
selectedIndexPath.take away(at: indexPath.row)
print(indexPath.row)
}
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let url = arraySplitArray[indexPath.row]
if url.absoluteString == “AD” {
return nil
}
let deleteAction = UIContextualAction(type: .damaging, title: “Delete”) { (contextualAction, view, boolValue) in
self.deleteData(at: indexPath)
}
let swipeActions = UISwipeActionsConfiguration(actions: [deleteAction])
return swipeActions
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
}
extension HistoryViewController : QLPreviewControllerDataSource {
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
return previewItem as QLPreviewItem
}
}
extension HistoryViewController {
func checkURLType(inputURL : URL) -> String {
// Most commom picture sorts..
let imageExtensions = [“png”, “jpg”, “gif”, “tif”, “JPG”, “PNG”,”HEIC”]
// Most cmmon video sorts..
let videoExtensions = [“WEBM”, “MPG”, “MPEG”, “MPE”, “MP4”, “M4P”, “M4V”, “AVI”, “WMV”, “MOV”]
let url: URL? = URL(fileURLWithPath: inputURL.path)
let pathExtention = url?.pathExtension
if imageExtensions.accommodates(pathExtention!) {
print(“Picture URL Historical past: (String(describing: url))”)
return “Picture”
}else if videoExtensions.accommodates(pathExtention!) {
print(“Video URL: (String(describing: url))”)
return “Video”
}else {
print(“Does Not Exist: (String(describing: url))”)
return “”
}
}
func generateThumbnail(path: URL) -> UIImage? {
do {
let asset = AVURLAsset(url: path, choices: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
imgGenerator.appliesPreferredTrackTransform = true
let cgImage = strive imgGenerator.copyCGImage(at: CMTimeMake(worth: 0, timescale: 1), actualTime: nil)
let thumbnail = UIImage(cgImage: cgImage)
return thumbnail
} catch let error {
print(“*** Error producing thumbnail: (error.localizedDescription)”)
return nil
}
}
}