Post

Replies

Boosts

Views

Activity

Reply to Screen size isn't working
it is not working That's not precise enough information. What do you get exactly ? to change constraints of top anchor and height of a view So constraints were previously defined ? How ? Please also show how you implement it. Show the code. Otherwise hard to say more than "there is likely an error in your code" …
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Learning Swift
When app launches, it loads the initial view (the one you have declared as entry point in storyboard). And this loads all the IBOutlets, IBActions, properties. When you tap on an object, it looks for action to execute… goes to another view… and so on. Note that SwiftUI has a different logic, where app manages states of objects and asks to draw UI according to these states.
Topic: App & System Services SubTopic: Core OS Tags:
Apr ’21
Reply to How to set up a expandable TableView Cell?
You should define     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) - CGFloat {         return // Compute the CGFloat row height, depending on the cell     } store in an array the state of the cells (in fact it should be included in the dataSource): var visibleBottomViews : [Bool] In viewDidLoad, you initialise it (all false for instance) When you show/hide a cell, you change corresponding value of visibleBottomViews. To do the computation, declare some global const for the class: let heightOfBottomView = CGFloat(30) // in fact the exact height of bottomView let basicHeight = CGFloat(44) // In fact the value you need let fullHeight = basicHeight + heightOfBottomView use it in the computation by testing visibleBottomViews[indexPath.row]     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) - CGFloat {         return visibleBottomViews[indexPath.row] ? fullHeight : basicHeight     } Note: in cellForRowAt func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell  { if indexPath.row == 2 { you only create cell for row == 2. What do you do for others ? You must define as well. If that works, don't forget to close the thread on the correct answer. Otherwise explain what's the remaining problem.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to How to set up a expandable TableView Cell?
Please, when you paste code, use Paste and Match Style to avoid extra lines: let heightOfBottomView = CGFloat(60) let basicHeight = CGFloat(50) lazy var fullHeight = heightOfBottomView + basicHeight var visibleBottomViews : [Bool] = [] func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) - CGFloat { if indexPath.row == 0 { //SegmentControl Rent of Buy return 60 } if indexPath.row == 1 { //Segment Control Property Types return 60 } if indexPath.row == 2 { //Price Slider return visibleBottomViews[indexPath.row] ? fullHeight : basicHeight } if indexPath.row == 3 { //Size Slider return 118 } } Error is probably line 18. Reason is that you have not populated visibleBottomViews array. You should In ViewDidLoad: visibleBottomViews = Array(repeating: false, count: 4) // The exact count should be the table rows count Note: I assumed all rows could have variable height. If variable size is only for row 2, you could replace the array by a single Bool line 5: var visibleBottomView = false and if indexPath.row == 2 { //Price Slider return visibleBottomView ? fullHeight : basicHeight }
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to Details of making an app
how an social media app like Instagram or Snapchat is actually developed? What do you mean ? Which language ? What is the purpose of your question ? If you want to do some similar app, you can develop in Swift with Xcode (I advise to use UIKit not SwiftUI). But take care, that is probably a be hard for the first app of an aspiring developer.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to UserDefaults with Struct - TableView not displaying data from saved from UserDefaults?
The problem is not UserDefaults but errors in your code (formatted with tool): struct Person: Codable { var firstName: String var lastName: String } class viewController: UIViewController { var newPerson = [Person]() override func viewDidLoad() { let person = [Person(firstName: "Peterson", lastName: "Jota") , Person(firstName: "John", lastName: "Paul")] let encoder = JSONEncoder() if let encoded = try? encoder.encode(person) { UserDefaults.standard.set(encoded, forKey: "savedPerson") } } } var person = [Person]() func tableView( tableView: UITableView, numberOfRowsInSection section: Int) - Int { return person.count } func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath) as! UITableViewCell cell.textLabel?.text = person[indexPath.row] return cell } Line 8, you declare newPerson but never use it. What is it for ? Line 12, you create person. But it does not exist outside of viewDidLoad. So line 25, person is empty. Hence return 0. And so, nothing is displayed in TableView. Some other comments for better readabilty Names of class should start with Uppercase : class ViewController person is an array, better name it persons. Declaration better be at beginning of class. So, more correct code: struct Person: Codable { var firstName: String var lastName: String } class ViewController: UIViewController { var newPerson = [Person]() // == Where do you use it ? var persons = [Person]() // renamed override func viewDidLoad() { // NOT Redeclare HERE let person = [Person(firstName: "Peterson", lastName: "Jota") , Person(firstName: "John", lastName: "Paul")] person = [Person(firstName: "Peterson", lastName: "Jota") , Person(firstName: "John", lastName: "Paul")] // Now, array is populated let encoder = JSONEncoder() if let encoded = try? encoder.encode(persons) { UserDefaults.standard.set(encoded, forKey: "savedPerson") } } } func tableView( tableView: UITableView, numberOfRowsInSection section: Int) - Int { return persons.count } func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath) as! UITableViewCell cell.textLabel?.text = persons[indexPath.row] return cell } If that works, don't forget to close the thread. Otherwise tell exactly what the remaining problem is and post more code if needed.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21