Different behaviour between Simulator and iPhone - iphone

I'm using DatePickerCell in my project with 7 date picker cells in a table view controller. I tweaked it so if i click on a new cell, the previously clicked cell date picker would collapse. When i run the app on the Simulator, everything is smooth and works as it's supposed to. When i run the app on my iPhone 5S running iOS 8.3, when i click on a cell, 2 cells expand and other weird things happen as well. What is wrong here ? Using Xcode 8.2.1 Swift 3
Here's the code for the tableview:
func dismissPreviousCell()
{
if previousIndex != nil {
let cellToDismiss = self.tableView(tableView, cellForRowAt: previousIndex!) as? DatePickerCell
cellToDismiss?.selectedInTableView(tableView)
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = self.tableView(tableView, cellForRowAt: indexPath)
if let datePickerCell = cell as? DatePickerCell {
datePickerCell.selectedInTableView(tableView)
print("Index path is \(indexPath)")
dismissPreviousCell()
previousIndex = indexPath
}
self.tableView.deselectRow(at: indexPath, animated: true)
}

Related

In iOS 15.2 UITableView cell height bug when add embedded view in swift

I have a project that works fine in xcode 12.5.1 and ios prior to 15.2 - it has UITableView with cells that contains embedded view. I set height of cells "not expanded" by default when loads UITableViewController and then expand them by tap on rows.
When I migrate to Xcode 13.2.1 and app works on ios 15.2 device it has a bug with cell height -
when UITableViewController loads and loads cells that contains embedded views then its height always set as a height of embedded view.
Maybe someone faced with this bug and have any solutions?
Code:
This is how I add cells -
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = cells[indexPath.section]![indexPath.row]
cell.layer.zPosition = CGFloat(indexPath.row)
cell.configure(with: models[indexPath.section]![indexPath.row])
if indexPath.section == 0
{
switch indexPath.row {
case 0:
cell.addEmbeddedView(Section.init())
default:
break
}
}
and this is how I "fix" size of cell to not expand before I tap on cell:
extension UITableView {
func fixCellBounds() {
DispatchQueue.main.async { [weak self] in
for cell in self?.visibleCells ?? [] {
cell.layer.masksToBounds = false
cell.contentView.layer.masksToBounds = false
}
}
}
and how I expand cell when tap on it:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath) as? MyTableViewCell else { return }
tableView.beginUpdates()
cell.expanded.toggle()
tableView.fixCellBounds()
tableView.endUpdates()
}
var expanded: Bool = false {
didSet {
let duration = CATransaction.animationDuration()
UIView.animate(withDuration: duration) {
self.arrow.transform = self.expanded ? CGAffineTransform(rotationAngle: .pi / 2) : .identity
self.height.isActive = !self.expanded
self.foldView.alpha = self.expanded ? 1 : 0
self.container.layoutIfNeeded()
}
}
}

Trying to bind an output to my tableviewCell UI Element in RxSwift

I have an output that lives in my VM and based on some change I want my textfield that resides in my custom tableviewCell to change in some way. I am unsure about how to have my UItextfield that lives in the tableviewcell bind to my output.
let index = IndexPath(row: 0, section: 0)
if let cell = tbl.cellForRow(at: index) as? TableViewCell {
print(cell.textF.text)
// Do whatever you want
}
I am not sure when you want to get the data, but if you want to do this when the user touches the cell, just implement the following method of UITableViewDelegate:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? YourTableViewCellClass {
let cellLabelText = cell.yourTextField.text
// Do whatever you want with cellLabel
}
}

get output frames failed, state 8196

When I try to customise a tableView cell, I found this error.
"Get output frames failed, state 8196"
I just have no idea it is the error from realm or from my customise tableView cell.
class StudentTableViewController: UITableViewController {
let realm = try! Realm()
var student: Results<StudentName>?
var selectedClass: ClassName? {
didSet {
load()
}
}
var selected: String = ""
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.title = selected
tableView.register(StudentTableViewCell.self, forCellReuseIdentifier: "studentName")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return student?.count ?? 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "studentName", for: indexPath) as! StudentTableViewCell
cell.name.text = student?[indexPath.row].name ?? "There are no student in this class"
cell.number.text = "\(student?[indexPath.row].studentNumber ?? 0)"
return cell
}
func load() {
student = selectedClass?.studentNames.sorted(byKeyPath: "studentNumber", ascending: true)
tableView.reloadData()
}
}
I think it did work when I am using Xcode 9 and Swift 4.1 but now in Xcode 10 it doesn't since it only show me this error and whole blank page of table view.
This error can be printed in the console when you use Realm even when you intend to only use it offline.
When the app is run in debug mode it will anonymously collect analytics, as stated in this answer: Realm Swift use locally only, however it still tries to connect online
To stop the error, click edit scheme, and add the environment variable REALM_DISABLE_ANALYTICS, and set it to YES as shown:
Environment variable screen
If you are using a Storyboard, you should not call tableView.register, you should simply set the reuseIdentifier for your prototype cell in storyboard.
If you have a separate .xib file for the cell, you should use:
tableView.register(nib: UINib?, forCellReuseIdentifier: String)
In other words the registration of your cell would be something like that:
self.tableView.register(UINib(nibName: "your cell nib name", bundle: nil), forCellReuseIdentifier: "your cell identifier")
If you have placed your cell in the tableview inside the controller that sits in the Storyboard then you do not need to register your cell, and as #Dávid Pásztor mentioned make sure you add the cell identifier to the cell in the Storyboard

Swift UIImageView not shown on device

I'm using following code to display an UIImageView in textFieldDidEndEditing:
let indexPath = IndexPath(row: 0, section: 0)
let cell = tableViewBodydata.cellForRow(at: indexPath) as! tvcell_Logbook
cell.imageViewArrow.isHidden = false
cell.imageViewArrow.image = UIImage(named: "same.png")
The code works perfectly on the iPhone X Simulator. But if im testing it on my iPhone X Device, the imageView isn't shown. The function is called correctly, I debuged it, but nothing happens. I reinstalled the App several times and also restarted the Device but nothing changed. Can anybody help me please?
Edit 1
I'm using this code in cellForRow:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: tvcell_Logbook!
if indexPath.row == 0 {
cell = tableView.dequeueReusableCell(withIdentifier: "CellWeight", for: indexPath) as! tvcell_Logbook
cell.imageViewArrow.isHidden = false
cell.imageViewArrow.image = UIImage(named: "same.png")
}
...
return cell }
And this code in textFieldDidEndEditing:
func textFieldDidEndEditing(_ textField: UITextField) {
let indexPath = IndexPath(row: 0, section: 0)
let cell = tableViewBodydata.cellForRow(at: indexPath) as! tvcell_Logbook
cell.imageViewArrow.isHidden = false
cell.imageViewArrow.image = UIImage(named: "same.png") }
If your filename is Same.png:
UIImage(named: "Same.png")
How is your picture named at filesystem?

Custom UITableViewCells repeating when navigating to viewcontroller

I am making a running app, and would like the user to see the races/marathons in their city. When clicking on the cell the user is navigated to a new view controller with details of the marathon. But upon pressing the back button to go back to the table the cells repeat. for example, if scrolling on the table it will display cell 1, cell 2,cell 3, cell 4,cell 1, cell 2,cell 3, cell 4 and will repeat more every time I navigate to the view controller with the table.
The code for the table is:
//MARK: TableView
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return exhibitions.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let singleCell: marathonTableViewCell = tableView.dequeueReusableCellWithIdentifier("marathonCell") as! marathonTableViewCell
singleCell.marathonName.text = exhibitions[indexPath.row]
singleCell.entryNumber.text = "\(entryNumber[indexPath.row])"
singleCell.entries.text = "\(entires[indexPath.row])"
return singleCell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("marathonDetail", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "marathonCardDetail"){
var upcoming: marathonDetailViewController = segue.destinationViewController as! marathonDetailViewController
let indexPath = self.marathonsTableView.indexPathForSelectedRow!
let currentCell = marathonsTableView.cellForRowAtIndexPath(indexPath) as! marathonTableViewCell
let marathonEvents = currentCell.marathonName.text
upcoming.nameMarathon = marathonEvents
self.marathonsTableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
I am using swift, Xcode 7, and Parse as my backend.
I think u have to init ur array before update tableview.
When u click back button, tableview may refresh.
So make some code that makes ur array new, and then call tableview.reloadData()