Post not yet marked as solved
Hi everyone,
ran into this problem:
there is a table view; it has a header view.
header view has 2 buttons
one button (expandButton) is clickable and the other (closeButton) is not
please help me figure it out
private(set) lazy var expandButton: UIButton = {
let button = UIButton()
button.setTitleStyled(buttonLabelText, fontName: Constants.robotoMediumFont, fontSize: appearance.expandButtonLabelSize, fontColor: appearance.textColor)
button.addTarget(self, action: #selector(expandLabel), for: .touchUpInside)
return button
}()
private(set) lazy var closeButton: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.setImage(UIImage(named: "24_x_24_close"), for: .normal)
button.addTarget(self, action: #selector(closeButtonTapped), for: UIControl.Event.touchUpInside)
return button
}()
@objc func expandLabel() {
print("Done")
let params: [AnyHashable : Any] = ["installationId": Constants.deviceUniqueId as Any, "product": product?.code as Any]
appMetricaFactory = factory.makeAppMetricaFactory()
appMetricaFactory?.sendRequest(name: "productShowMoreDescription", parametrs: params)
if CardConst.expandedState == .collapsed {
CardConst.expandedState = .expanded
} else {
CardConst.expandedState = .collapsed
}
ProductCardViewController.shared?.updateView()
}
@objc func closeButtonTapped(_ sender: UIButton) {
print("Tapped")
ProductCardViewController.shared?.customizeView()
onClose?()
}
Post not yet marked as solved
When the application is launched, the compiler gives out this information : (When the application is launched, the compiler gives out this information (2020-07-29 13:42:26.411510+0300 News App[1538:86650] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x60400028c800 UILabel:0x7f8c114113e0'News App'.top >= UILayoutGuide:0x6000001bfaa0'TitleView(0x7f8c11512ef0)'.top (active)>",
"<NSLayoutConstraint:0x60400028c710 UILabel:0x7f8c114113e0'News App'.firstBaseline == UILayoutGuide:0x6000001bfaa0'TitleView(0x7f8c11512ef0)'.top + 28 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400028c800 UILabel:0x7f8c114113e0'News App'.top >= UILayoutGuide:0x6000001bfaa0'TitleView(0x7f8c11512ef0)'.top (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.), I cannot figure out what I am doing wrong, I have arranged all the constraints
referring to the project :https://github.com/dmitrySachkov/NewsApp), I cannot figure out what I am doing wrong, I have arranged all the constraints
referring to the project : https://github.com/dmitrySachkov/NewsApp
Post not yet marked as solved
Hello, i just started lern the Swift4 and have this trouble, i try use SerchBar and have error (2019-09-07 15:28:18.604943+0300 Todoey[2177:112494] [Common] _BSMachError: port 7403; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND")How i can fix it?import UIKit
import CoreData
class TodoListViewControllerist: UITableViewController {
var itemArray = [Item]()
// let dataFilePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("Items.plist")
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
override func viewDidLoad() {
super.viewDidLoad()
// print(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("Items.plist"))
// let newItem = Item()
// newItem.title = "Mike"
// // newItem.done = true
// itemArray.append(newItem)
//
// let newItem2 = Item()
// newItem2.title = "Bob"
// itemArray.append(newItem2)
//
// let newItem3 = Item()
// newItem3.title = "Charl"
// itemArray.append(newItem3)
loadItems()
// if let items = defaults.array(forKey: "TodoListArray") as? [Item] {
// itemArray = items
// }
}
//MARK - TableView Datasource Methods
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = itemArray[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoItemCell", for: indexPath)
cell.textLabel?.text = item.title
//Ternary operator ==>
//cell.accessoryType = item.done == true ? .checkmark : .none
cell.accessoryType = item.done ? .checkmark : .none
// if item.done == true {
// cell.accessoryType = .checkmark
// }else{
// cell.accessoryType = .none
// }
return cell
}
//MARK - TableView Delegate Methods
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// context.delete(itemArray[indexPath.row])
// itemArray.remove(at: indexPath.row)
itemArray[indexPath.row].done = !itemArray[indexPath.row].done
saveItems()
// if itemArray[indexPath.row].done == false {
// itemArray[indexPath.row].done = true
// }else{
// itemArray[indexPath.row].done = false
// }
//
// if tableView.cellForRow(at: indexPath)?.accessoryType == .checkmark {
// tableView.cellForRow(at: indexPath)?.accessoryType = .none
// }else{
// tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
// }
// tableView.reloadData()
tableView.deselectRow(at: indexPath, animated: true)
}
//MARK - Add New Item
@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {
var textField = UITextField()
let alert = UIAlertController(title: "Add New Todoy Item", message: "", preferredStyle: .alert)
let action = UIAlertAction(title: "Add Item", style: .default) { (action) in
let newItem = Item(context: self.context)
newItem.title = textField.text!
newItem.done = false
self.itemArray.append(newItem)
self.saveItems()
// self.defaults.set(self.itemArray, forKey: "TodoListArray")
}
alert.addTextField { (alertTextField) in
alertTextField.placeholder = "Create new item"
textField = alertTextField
}
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
//MARK - Model Manipulation Methods
func saveItems () {
do {
try context.save()
}catch{
print("Error saving context \(error)")
}
self.tableView.reloadData()
}
func loadItems(with request : NSFetchRequest<Item> = Item.fetchRequest()) {
// if let data = try? Data(contentsOf: dataFilePath!) {
// let decoder = PropertyListDecoder()
// do {
// itemArray = try decoder.decode([Item].self, from: data)
// }catch{
// print("Error \(error)")
// }
// }
// let request : NSFetchRequest<Item> = Item.fetchRequest()
do {
itemArray = try context.fetch(request)
}catch{
print("Error fetching data from context \(error)")
}
}
}
extension TodoListViewControllerist : UISearchBarDelegate {
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
let request : NSFetchRequest<Item> = Item.fetchRequest()
request.predicate = NSPredicate(format: "title CONTAINS[cd] %@", searchBar.text!)
request.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)]
loadItems(with : request)
// do {
// itemArray = try context.fetch(request)
// }catch{
// print("Error fetching data from context \(error)")
// }
// tableView.reloadData()
}
}