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 :)
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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!
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
}
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)
}
}
}
Hello everyone, my iPhone keep on showing multiple "Trust this Computer" alert simultaneously which I cannot tap on it to Trust. As a result, I cannot run my XCode project on my device. Does anyone has any ideas or solutions to fix this ?
Solution I have tried:
Reset Location & Privacy
Reset Network Settings
Enable Developer Mode
Restart Device
My devices specs:
iPhone 15 Pro: iOS 18.2.1
Macbook Pro M3 Max: Sequoia 15.1.1
Topic:
Developer Tools & Services
SubTopic:
General