Post

Replies

Boosts

Views

Activity

tableview.reloadRows() takes three hit to reload
I am trying to update my array data and reload the tableview once user click on a cell, however, it takes three hits till the tableview reload a specific row that was selected. This problem only occur when I use (tableview.reloadRows()) but if I use (tableview.reloadData()) everything is working fine with just a single click but I don't want to reload the entire tableview. Can someone please tell me what I did wrong? extension ViewController: UITableViewDataSource, UITableViewDelegate {     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return dummyData.count     }     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         let todoCell = tableView.dequeueReusableCell(withIdentifier: "todoCell") as! TodoTableViewCell         todoCell.dataLabel.text = dummyData[indexPath.row].item         if (dummyData[indexPath.row].done == false) {             todoCell.dataLabel.hideStrikeTextLayer()         }else{             todoCell.dataLabel.strikeThroughText()         }         todoCell.delegate = self         return todoCell     }     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         let index = IndexPath(row: indexPath.row, section: 0)         if dummyData[indexPath.row].done == false {             dummyData[indexPath.row].done = true             todoTableView.reloadRows(at: [index], with: .none)              }else {             dummyData[indexPath.row].done = false             todoTableView.reloadRows(at: [index], with: .none)         }     } }
16
0
2.9k
Jan ’21
Does this kind of sending data violate MVC?
I need to send data from HomeVC to ResultVC using segue, is this kind of method violate MVC? Inside the ResultVC I created two store properties so that I can access to it in the prepare(for segue: UIStoryboardSegue, sender: Any?) method in HomeVC, can anyone please tell me whether this kind of method violate MVC? Your responses will be highly appreciate! class HomeVC:UIViewController {     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {         if segue.identifier == C.segueToResultVC {             let resultVC = segue.destination as! ResultVC             resultVC.totalSplit = calculator.getSplit()             resultVC.splitInfo  = calculator.splitInformation()         }     } } class ResultVC:UIViewController {     var totalSplit:String?     var splitInfo:String?     override func viewDidLoad() {         super.viewDidLoad()         customizeViews()     }     override func viewWillAppear(_ animated: Bool) {         totalPrice.text = totalSplit         splitAndTip.text = splitInfo     }
2
0
209
Dec ’20
Unexpectedly Found nil On TableView While Moving From ParentVC to ContainerVC
I have a problem with moving from parent viewcontroller to a container viewcontroller. My container viewcontroller has a UITableView inside it and whenever I try to switch to it from the parent viewcontroller it always return nil, saying that the UITableView doesn't exist. I know that this problem is probably related to the UITableView is not available yet during the time when I were trying to move into the container viewcontroller. I try to move the setup code into ViewWillAppear but still it doesn't help so I assume this to be a kind of problem where the UITableView is not available yet to show on the screen. Below is my code:     func showSearchAccountVC() {         print("Begin to move into SearchAccountVC")         let searchAccountVC = SearchAccountViewController()                  addChild(searchAccountVC)         self.view.addSubview(searchAccountVC.view)                  searchAccountVC.didMove(toParent: self)         searchAccountVC.view.frame = self.view.bounds     } // MARK: This is in container viewcontroller class SearchAccountViewController: UIViewController {     @IBOutlet weak var searchAccountTableView: UITableView!          override func viewDidLoad() {         super.viewDidLoad()         self.view.backgroundColor = .red         // Do any additional setup after loading the view.         //self.view.backgroundColor = .red         searchAccountTableView.separatorStyle = .none         searchAccountTableView.estimatedRowHeight = 100         searchAccountTableView.rowHeight = UITableView.automaticDimension         searchAccountTableView.delegate = self         searchAccountTableView.dataSource = self     } } Can someone tell me how would I solve this kind of problem? Your response will be highly appreciated!
5
0
1.7k
Dec ’20
How does modifying an array work?
I have an array of a struct and I have to modify a property inside the struct whenever user switch between each index of the SegmentControl, for example: // Struct struct User { var name: String var age:Int } // Array var arrayUser = [User(name: "Alex", age: 23] // Modify an array arrayUser[0].age = 19 Will the array create a new copy every time I modify like this or it just reference to that particular element and make a modification? Your response would be highly appreciated :)
1
0
235
Nov ’20
Error code: Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee3239efc)
I am trying to access a label in a viewcontroller from a model class so that I can change the UILabel text every time there is an error, however, every time I create the viewcontroller object inside the model class this error always appear. If i delete the object declaration then everything will work just fine. Can anyone tell me how to solve this problem? Your comment will be highly appreciate! Model import Foundation import Firebase class SignUp{          let db = Firestore.firestore()     var emailTextFieldCopy:UITextField!     var passwordTextFieldCopy:UITextField!     var fullnameTextFieldCopy:UITextField!     var usernameCopy:UITextField!          var errorText:String?     var eError:String?          let sup = SignUpVC() // here what caused the error          //MARK: - SignUp     func signUp(email:String, fullname:String, username:String, password:String){                   Auth.auth().createUser(withEmail: email, password: password) { (authResult, error) in             if let error = error {                 let errorText = error.localizedDescription                 if errorText == "The email address is badly formatted."{                     DispatchQueue.main.async {                         self.errorEmail()                                              }                 } else if errorText == "The password must be 6 characters long or more."{                     DispatchQueue.main.async {                         self.errorPassword()                     }                                      }                 print(errorText)             }else {                 //self.clearTextFieldColor()                 let userID = Auth.auth().currentUser?.uid                 var add = self.db.collection("userinfo").document(userID!).setData(["fullname" : fullname,                     "username": username])             }         }     } ViewController import UIKit import Firebase class SignUpVC: UIViewController{     @IBOutlet weak var emailTextField: UITextField!     @IBOutlet weak var passwordTextField: UITextField!     @IBOutlet weak var fullNameTextField: UITextField!     @IBOutlet weak var userNameTextField: UITextField!     @IBOutlet weak var facebookBtn: UIButton!     @IBOutlet weak var signupBtn: UIButton!     @IBOutlet weak var errorText: UILabel!          let db = Firestore.firestore()     var signUp = SignUp()     var err:String = ""          override func viewDidLoad() {         super.viewDidLoad()                  facebookBtn.layer.cornerRadius = facebookBtn.frame.height/5         signupBtn.layer.cornerRadius = signupBtn.frame.height/5         signUp.emailTextFieldCopy = emailTextField         signUp.passwordTextFieldCopy = passwordTextField         signUp.fullnameTextFieldCopy = fullNameTextField         signUp.usernameCopy = userNameTextField              }          override func viewWillAppear(_ animated: Bool) {         errorText.text = err     }
0
0
282
Jul ’20