I have these two files i want to talk to each other via delegate protocol. I want to take a list of strings from KeyboardViewController into another list of strings in tab2 (Which is the main viewController) when i click on a value in my tableView
I have made a protocol in KeyboardViewController and made my function and set my deligate function in the tableView( didSelectRowAt indexPath) to pass it into tab2, where the function reads the input from the other KeyboardViewController and appends it to a list
The print for the delegate commands prints the text successfully, while the protocol function can't get run the print command which tells me that the textChoice dosen't run.
When i enter the tab2 tableView the app just crashes (Crashlog in the bottom)
How do i successfully transfer my Strings via delegate to append it to a list in another file, without my tableview crashing.
I have my KeyboardViewController here
import UIKit
import UIKit.UIGestureRecognizerSubclass
protocol icebreakerData {
func textChoice(string: String)
}
class KeyboardViewController: UIInputViewController, UITableViewDelegate, UITableViewDataSource {
var iceBreakerDataDelegate: icebreakerData!
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Lines.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel!.text = Lines[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let row = indexPath.row
self.textDocumentProxy.insertText(Lines[row])
iceBreakerDataDelegate?.textChoice(string: Lines[row]) // < ----This is where i suspect the issue
print("Hello ther")
}
func tableView(_ tableView: UITableView,
heightForRowAt indexPath: IndexPath) -> CGFloat {
// Make the first row larger to accommodate a custom cell.
return 80
}
@IBOutlet var tableView: UITableView!
var Lines: [String] = [
"text sample for the keyboard",
]
func makeRandom() {
Lines.shuffle()
}
// -----------------------------------------------------
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
makeRandom()
tableView.dataSource = self
tableView.delegate = self
}
@IBAction func fjern(_ sender: Any) {
for _ in 1..<200 {
self.textDocumentProxy .deleteBackward()
}
}
}
There is my swiftfile tab2 which is a viewController as well
import UIKit
class tab2: UIInputViewController, UITableViewDelegate, UITableViewDataSource, icebreakerData {
func textChoice(string: String) {
likedList.append(string)
print("I got it yes yes")
}
var likedList: [String]! = []
@IBOutlet var tableView: UITableView!
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return likedList.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel!.text = likedList[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
func tableView(_ tableView: UITableView,
heightForRowAt indexPath: IndexPath) -> CGFloat {
// Make the first row larger to accommodate a custom cell.
return 80
}
//-----------------
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
tableView.dataSource = self
tableView.delegate = self
let selectionVC = self.storyboard?.instantiateViewController(withIdentifier: "tab2") as? KeyboardViewController
selectionVC?.iceBreakerDataDelegate = self
navigationController!.pushViewController(selectionVC!, animated: true)
self.present(selectionVC!, animated: true)
}
}
2020-06-12 02:46:05.968724+0200 OpenUP[7306:281686] Failed to inherit CoreMedia permissions from 7300: (null)
2020-06-12 02:46:05.993400+0200 OpenUP[7306:281566] [Storyboard] Unknown class _TtC6OpenUP5round in Interface Builder file.
2020-06-12 02:46:05.993650+0200 OpenUP[7306:281566] [Storyboard] Unknown class _TtC6OpenUP5round in Interface Builder file.
2020-06-12 02:46:05.994642+0200 OpenUP[7306:281566] Failed to set (borderWidth) user defined inspected property on (UITableViewCell): [<UITableViewCell 0x7f84eac07ca0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key borderWidth.
2020-06-12 02:46:05.994781+0200 OpenUP[7306:281566] Failed to set (borderColor) user defined inspected property on (UITableViewCell): [<UITableViewCell 0x7f84eac07ca0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key borderColor.
2020-06-12 02:46:05.994902+0200 OpenUP[7306:281566] Failed to set (borderWidth) user defined inspected property on (UITableViewCellContentView): [<UITableViewCellContentView 0x7f84ead0b190> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key borderWidth.
2020-06-12 02:46:05.995017+0200 OpenUP[7306:281566] Failed to set (borderColor) user defined inspected property on (UITableViewCellContentView): [<UITableViewCellContentView 0x7f84ead0b190> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key borderColor.
2020-06-12 02:46:05.996690+0200 OpenUP[7306:281566] [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:0x6000023e54a0 UITableViewCellContentView:0x7f84ead0b190.width == 320 (active)>",
"<NSLayoutConstraint:0x6000023d9860 'UIView-Encapsulated-Layout-Width' UITableViewCellContentView:0x7f84ead0b190.width == 414 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000023d9860 'UIView-Encapsulated-Layout-Width' UITableViewCellContentView:0x7f84ead0b190.width == 414 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.