I work with swift 3 for macOS and I have a general question. In my Storyboard are two View Controllers with a tableview for each View Controller.
Example: View Controller A > VC_A.class View Controller B > VC_B.class
Both View Controllers are elements of one Split View Controller. now i would like to put one row element form VC A to VC B via drag and drop. this works fine, if both VC are in one class.
but now i would like to split it like the example below (VC_A and VC_B.class)
but how can i control the iboutlet tblview of VC_A in the VC_B.class?
You could use delegates and protocols for this. Setup a protocol class with your interface for editing tables eg
protocol EditableTableView {
func insertCell()
}
For both of your ViewControllers, set them to adhere to this protocol, implement the insertCell function and also add a delegate pointer.
class ViewControllerA : EditableTableView {
func insertCell() {
... add your code to insert a cell into VC A...
}
weak var otherTableViewDelegate : EditableTableView?
}
class ViewControllerB : EditableTableView {
func insertCell() {
... add your code to insert a cell into VC B...
}
weak var otherTableViewDelegate : EditableTableView?
}
In your parent split VC you can setup the delegate pointers so they point to the other view controller
viewControllerA.otherTableViewDelegate = viewControllerB
viewControllerB.otherTableViewDelegate = viewControllerA
Now whenever you want to insert a cell in the other controller you can call
self.otherTableViewDelegate?.insertCell()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With