How to make sidemenu in swift (subSidemenu - ios

I made sidemenu. but i have some question. when i clicked button on the sidemenu, appear an other side button.
look like this image
when i clicked sidemenu button, appear subSidemenu.
I don't know how to say this function.

Firstly if you want to show a list of values which are collapsable then you need a UITableView. Make your SideMenus as sections and rows as SubSideMenus.
And you would like to have that feature when user tap so implement tableview's numberOfRows method like this
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let sideMenu = mySideMenus[section]
return sideMenu.isCollapsed ? 0 : sideMenu.subSideMenus.count
}
And when the header is tapped you need to call tableView.reloadSections(sections: [IndexSet], with: UITableViewRowAnimation) to reload that section.
I don't know if this is was your exact question but sidebar is easy to implement for your app. And you don't need buttons when working with tableView.

Related

How to pin to top in a TableView in Swift?

I have a tableView with hundreds of cells. I want to add a feature to pin to top favorite cells, for example by swipe. Is there a way to do that? Or is it easier to have a different tableView with favorite cells?
Section for this.
Add your favorites to view, you can create it using storyboard or programmatically using following code. If you use storyboard, create and make a reference to the tableViewController and just return in this code.
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
// create and return yourView
}

Expandable Tableview with last row of every section has Add Button - Swift

I struck in tableview. I need tableview of collapse and Expand looks like Below,
]2
I need to add 2 buttons for last row of every section.
Could you guide me how to design the below design in ios swift?
Add your buttons in custom view and feed it in UITableViewDataSource method below:
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
Best way is take Two Button in one cell, and return that cell when indexPath.row = lastRow
And add tap gesture on header view for collapse view
You can create a cell with two buttons. Next you should add it to your data source and configure it properly. Then add a delegate to your custom UITableViewCell and handle taps.

Swift - override Edit button function

I have a UITableView, which comes prefitted with an Edit button (UITableView.editButtonItem()). When pressed, it toggles to "Done", and you get those red minus signs next to entries for when you want to delete them.
I want to attach custom code to the button so that when you click it, you don't get the red minus signs. When in edit mode, whenever you click on an entry, it brings up a UIActionSheet or a UIAlertController to allow you to make the changes.
So, I want to override the Edit button so that when clicked:
The red minus "Delete" icons don't show up
The cells become selectable.
I've tried creating a custom UIBarButtonItem, but that's a terrible walkaround. I think what I want is do-able, I'm just not sure how.
Use delegate for UIViewController and make custom code on the events of that button. If it is on every row you must attach tap action from the code during cell generation.
I myself would preffer to have custom class.
I've figured out which methods to call:
// The following two functions remove the red minus sign
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.None
}
override func tableView(tableView: UITableView, shouldIndentWhileEditingRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
// The following property allows you to select cells while in editing mode
self.tableView.allowsSelectionDuringEditing = true

How to make the first row of an UITableView a header of a section?

I have an UITableView with custom cells. I would like that the first row is always visible. As I have only once section, I thought of making a header but in this case I don't really know how to do it?
Is it possible to make a header from the first row with the same gesture recognizers, same dataSource behind the rows, briefly, have the header exactly like th row, just as if the row was pined to the top of the tableView?
You should use a header, or a separate view outside the table view. You can use the same gestures (generally, though not the delete) and data source.
If you want it all, you could use 2 table views- the first with one section and one row, the second with all the other data. It would be easiest if your data source was broken down in a similar way in the view controller.
In either case you can achieve what you want, but not by flicking a switch, you will need to add some logic and different views to make it happen.
If you want to make one static cell that is pinned to the top but in all other ways the same to the others, you could simply add one to your numberOfRowsInSection
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count + 1
}
Then when you display the cells, check for the row number and always set the first row to contain your static header content.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row == 0 {
// Create or set static cell content.
}
}
The other way is to create a custom section header and set it using viewForHeaderInSection
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
var view = UIView()
view.backgroundColor = UIColor.blueColor()
return view
}
return nil
}

How to display and hide table view cells in swift

I have a tableView with two different custom cell. One cell have few textfields data and other also have different textfield data,here i need to collapse and hide the each cell. i don't know how to do this.Please let me know.
https://maniacdev.com/2013/03/an-open-source-ios-control-allowing-you-to-create-great-looking-collapsible-lists-without-uitableview
Please refer the above link, i want the same in swift.
Thanks in advance
So you want to hide one of your UITableViewCells?
Ill think the easiest way is to add some more information to your "Row Data Array".
For example:
You have 10 Columns, and you want to hide 4 Specific Column. You have a function called "getRowData" - this returns (when no filter is selected) all 10 Rows. When you tap on a button, you could change your "getRowData" function to return only the 4 Rows you want.
With the example you showed above - you want some collapsible Lists, based on an UITableViewController.
So you have (In this example) 3 Main Categories - and if the User click on one "Title" you want to expand the list for this Category.
So you could use Sections - create a Section for each Category. Then implement something like this:
// create a main variable for your "activated Category"
var enabledCategory:Int = 0 // you could add i base value
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let indexPath = tableView.indexPathForSelectedRow();
enabledCategory = indexPath.row;
....
Check here which section was clicked by the user. If (for example "0" - so the first one, expand this section. So do something like this:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if(indexPath.section == enabledCategory) {
return rows // return rows you want to show
}
You need also to change the count of rows in here:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 3
}
this should be (in your example) always 3.
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
This depends on your section // Category

Resources