I have two ASTableNode
1. Notifications tabelNode
2.Comments tabelNode
now I want to make a segment controller as a sticky header on the table, when I click on Notifications segment the notificationTable should appear and when I click on comments segment the commentsTable should appear as in this image WatchList and Following Segment,How can I achieve this any help appreciated.
Asked
Active
Viewed 410 times
2

Sipa
- 383
- 1
- 13
-
you can do this by creating two `ASButtonNode` instead of `Segment controller` and below the `ASButtonNode` you can place two different `ASTableNode` with the size and hide and show according to the button tapped. – swetansh kumar Nov 10 '17 at 07:17
-
– swetansh kumar i made buttonNode in tableNode cell, how i grab actions in a cellNoe? – Sipa Nov 10 '17 at 19:25
-
make a protocol in the `cellNode` containing a func in it. `protocol namedDelegate : class { func btnClicked(_ value : String) }` then define `func p_btnClicked(_ sender : ASButtonNode) { delegate?.btnClicked(value!) }` and now add it the button target. now use the delegate in the table node for further actions. – swetansh kumar Nov 11 '17 at 19:01
-
did you try the solution which I suggested above? – swetansh kumar Nov 12 '17 at 15:19
-
why sticky header? why not just above table? Or best way above 2 view controllers. – Bimawa Dec 07 '17 at 07:02
1 Answers
1
A bit late to the party, but hope this helps. It's not difficult at all to use native views for displaying nodes. Here is how it's done for the segment control:
///Keep a reference to the segment control
private var segmentedView: UISegmentedControl?
///This node will contain the segment control
private lazy var segmentedNode: ASDisplayNode = {
///The node is initialized with a view block that initializes the segment
return ASDisplayNode(viewBlock: { () -> UIView in
self.segmentedView = UISegmentedControl(items: ["Watchlist", "Following"])
///Select Watchlist maybe? Your call.
self.segmentedView.selectedSegmentIndex = 1
///Configure additional appearance of the segment control
return self.segmentedView
})
}()
After that, do any node operations you want (i.e. include in stack view, set style) on the node, and any segmented control operations you want (i.e. value changed selector) on the native control.

Dog
- 474
- 8
- 25