Post

Replies

Boosts

Views

Activity

Reply to tableview.reloadRows() takes three hit to reload
Could you show code for hideStrikeTextLayer() and strikeThroughText() Note that you could simplify code: 				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) 				} with dummyData[indexPath.row].done.toggle() todoTableView.reloadRows(at: [index], with: .none) Also try to call reloadRows in a 		DispatchQueue.main.async { } as you did for reloadData() When you paste code, please use Paste and Match Style, to avoid all the extra lines that make it nearly impossible to read. import UIKit import SwipeCellKit import StrikethroughLabel class ViewController: UIViewController { 		private var todoTableView	 = UITableView() 		private var searchBar			 = UISearchBar() 		 		private var dummyData = [Data(item: "Go to shopping", done: false), 														 Data(item: "Go to school", done: false), 														 Data(item: "Buy milk", done: false), 														 Data(item: "Do homework", done: false), 														 Data(item: "Clean room", done: false), 														 Data(item: "Wash car", done: false)] 		 		override func viewDidLoad() { 				super.viewDidLoad() 				view.backgroundColor = .white 				title = "Todoist" 				 				setupViews() 		} 		 		private func setupViews() { 				view.addSubview(todoTableView) 				view.addSubview(searchBar) 				 				navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addItem)) 				 				searchBar.translatesAutoresizingMaskIntoConstraints																												 = false 				searchBar.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 0).isActive	 = true 				searchBar.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive					 = true 				searchBar.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: 0).isActive = true 				 				todoTableView.delegate					= self 				todoTableView.dataSource				= self 				todoTableView.register(TodoTableViewCell.self, forCellReuseIdentifier: "todoCell") 				 				//todoTableView.allowsSelection	 = true 				todoTableView.rowHeight					 = 70 				//todoTableView.separatorStyle		= .none 						 				todoTableView.translatesAutoresizingMaskIntoConstraints																										 = false 				todoTableView.topAnchor.constraint(equalTo: searchBar.bottomAnchor, constant: 0).isActive									 = true 				todoTableView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 0).isActive		 = true 				todoTableView.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: 0).isActive	 = true 				todoTableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: 0).isActive = true 		} 		 		@objc private func addItem() { 				 				var dataFromTextField:UITextField? 				var addButton:UIAlertAction! 				 				let addItemBox = UIAlertController(title: "Add Item", message: .none, preferredStyle: .alert) 				addItemBox.addTextField { (item) in 						dataFromTextField = item 				} 				addButton = UIAlertAction(title: "Add", style: .cancel) { (action) in 						if let data = dataFromTextField?.text, !data.isEmpty { 								self.dummyData.append(Data(item: data, done: false)) 						} else { 								self.dismiss(animated: true, completion: nil) 						} 						DispatchQueue.main.async { 								self.todoTableView.reloadData() 						} 				} 				addItemBox.addAction(addButton) 				present(addItemBox, animated: true, completion: nil) 		} } extension ViewController: UITableViewDataSource, UITableViewDelegate, SwipeTableViewCellDelegate { 		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 // Not sure it is needed 				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) 				} 		}
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Make UIScrollView Move Two Directions
View scrolls in a direction only if the content is larger in a direction than the scrollView. What you do usually: create a View (will be the content view) place objects (as image, labels, …) inside, that will scroll embed the contentView in a Scroll View. You can also create the ContentView and place inside ScrollView (if you have not selected to embed) Create a ScrollView in IB Drag a UIView (this is the content View) inside the scrollView (appears inside Scroll in the object hierarchy) In any case, scroll capability depends on the relative size of ContentView and scrollView. I had written a small memo for myself, on how to set constraints, hope it will help. Building a ScrollView with its constraints ScrollView is composed of a scrollview, a content view and objects in content view to be scrolled. One need to have the concept clearly in mind:         - it is the contentView which contains all of what will be displayed         - the scroll is a window that "passes over" the content to reveal part of it         - and yet contentView is set INSIDE ScrollView, which may be misleading it will scroll in one direction only if the content is larger than the scrollView in that direction the contentView should be set to include « exactly » all that should be showable. If too large, it will scroll beyond the content and we will see an empty area For the ScrollView : Define its dimensions by constraints relating to the Safe area             leading = 0             trailing = 0             top = maybe non zero if you scroll a part of the screen             bottom = 35 (here to leave room for some buttons below) you can keep the content layout and frame layout ON Define now the constraints of UIView relative to the scrollView (Superview)          leading = 0          trailing = 0          equalWidth with Scroll if we don't want horizontal scroll. DON'T do this if you want horizontal scroll           top = 0           bottom = 0           equalHeight with Scroll if we don't want vertical scroll. DON'T do this if you want vertical scroll     Define the dimension constraints of the ContentView to correspond to the complete content you have to put inside (the content that will scroll)           height =           width = Note: this is necessary to eliminate red warnings from IB Place objects in the ContentView for each Define the constraints relative to the ContentView.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to CGAffineTransform breaks safe area insets in iOS 14?
I tested on a sample app. I did not notice the issue. I tested the following override func viewDidLoad() { 				super.viewDidLoad() 				print("at load", tableView.safeAreaInsets) 				tableView.transform = CGAffineTransform(scaleX: 1, y: -1) 				print("after transform", tableView.safeAreaInsets) 		override func viewLayoutMarginsDidChange() { 				super.viewLayoutMarginsDidChange() 				print("layout changed", tableView.safeAreaInsets) 		} I get the following prints (viewLayoutMarginsDidChange called twice) At load at load UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) after transform UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) layout changed UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) layout changed UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) After rotation layout changed UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) layout changed UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) After rotating back layout changed UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) layout changed UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) Could you do the same test and report results ?
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’21
Reply to Make UIScrollView Move Two Directions
I see what your saying but how come in my experience the view can scroll in a direction where the content is smaller instead of larger?  Which content exactly ? In the hierarchy (as seen in IB), you have: ScrollView      View (the content view)            objects inside the content view (for instance, image) It is the size of the contentView, not the size of the image inside the content view.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21