Swift Add custom cell on button tap - swift

I have a table view with one custom cell that I have already built and hooked up. When the user taps the add cell button I want it to add a different custom cell. I don't know where to start this process. Do I build it on the storyboard then hide it? Or what is the best means?

You should create all of your custom cells in the storyboard, and then implement UITableViewDataSource methods, where you return whatever cells you want.
Check out the documentation

Related

How to create my own UIAlertController in Swift 5?

I have graphic that I would like to create as a UIAlertController? Can I create a xib and then call that file to present it? What is the best way to do this?
An alert is nothing but a presented view controller. So make your own view controller and call present. It's as simple as that.
You can create a subclass of UIView and its corresponding Xib.
Just create an instance whenever you need to use it and just add it as a subview.
And on the tap of close button just remove it.
Make sure that you create a method in the UIView subclass, which accepts the text, and the button titles, and call the method whenever you are adding it.
So you can add dynamic button titles or texts if the same popup is being used in multiple places in your application.

How to add an "Add Button"- Button

I'm looking to make a button which creates new buttons.
So there are already 3 buttons created by me with ViewController.
And on the bottom should be a "create new button" button. So the user can create as many buttons as he wishes. And every new button should be stacked under each other.
https://imgur.com/ttDZQU1
Here is how I build it on ViewController.
You have some ways to achieving this result. You can create a stack view and push the buttons to it. You can programatically add buttons to the screen by creating new UIButtons every time the users click the add button, or you can create a table view, and add a new cell every time the user clicks it. This last approach already supports scrolling (For when your user clicks tens of times, you'll need to able to scroll the screen so they can see the buttons outside the visible frame). In case you choose to go with the first or second, don't forget to add an UIScrollView to your View.
The steps to get this result with a tableview (3rd approach are):
Create a UITableView in the view controller's storyboard.
Set the UITableView datasource and delegate to the view controller
Create a UITableViewCell inside the UITableView, and set its identifier to something related to cell, like "buttonCell", for example.
Add a UIButton to this newly created UITableViewCell, and pin the constraints accordingly.
in the View Controller .swift file, create an outlet for the UITableView
in the tableView delegate cellForRowAt, don't forget to use the right identifier (in our example, "buttonCell").
if you get lost somewhere in the steps listed above, check some tutorials to create a tableview, such as: https://www.ralfebert.de/ios-examples/uikit/uitableviewcontroller/

Edit and add button for UITableView in ViewController

I have a little problem, I want to add a function to two BarItems in my UINavigationBar, which is placed above the UITableView in a normal ViewController. I'm very new to programming so can you please give me the complete code that I need? The functions I want to have are:
An edit button so I can delete and change the data of a cell (title + subtitle)
An add button so I can add a new cell to my UITableView. Maybe also a function that points to another ViewController where I can type the data for Title and subtitle to save it afterwards.
Thanks!
For editing record:
You cannot get the cell that your planning to edit using button on UINavigationController, the buttons should be placed at the same cell on your UITableview to edit that specific cell. and in this way you need custom UITableviewcell.
For creating new record :
First link the button to your UIViewController class as Action.
You can append the array that your using to fill the UITableview and then call your UITableview like to refresh the data:
self.tableview.reloadData()
For presenting another UIViewController:
First drag new ViewController in your storyboard and link the button on the first ViewController into your new UIViewController and choose segue as "Show".
To save your data its a big topic you have either NSUserDefaults or CoreData so Google it.
Note : linking means by pressing ctrl-drag with mouse to your target.
Update :
Download your sample from here : https://yadi.sk/d/EJf610XWhkxDT

Having UITableView edit button outside of the navigation bar

I have a UIViewController, and within that view i have UITableView added in IB
The UITableView displays the items from my array beautifully
I would like to be able to edit the items i.e delete them
BUT The UITableView does not have a navigation bar, and i am not using a navigation controller within this app i am just adding and removing views manually.
What i would like to do is place an "edit" button somewhere else within the view ... is this possible? and how might i go about this?
Put a button somewhere. In an action connected to it set TableView's editing property to YES - it should work fine. You also need to implement delegate's editingStyleForRowAtIndexPath method (return UITableViewCellEditingStyleDelete to allow to delete cells).
You could make one special cell (e.g. 1st row, 1st group) a button by implementing a adaequate didSelectRowAtIndexPath.
Or you could put buttons for editing/deleting in each cell (if single deletion/editing makes sense).
Or you could place the UIIableView on a super view wich also contains the button(s) as sub views.

Customizing UITabBarController

I need to change font size and background color of the list displayed by "More" button of the UITabBarController. Is it possible ? How can I do it ?
Thanks a lot.
UITabBarController has a property called moreNavigationController, the root view of which is presumably the UITableView you see when you tap the "More" button.
If you want to customize the table view cells, you'll need to reassign its dataSource to an object you control. But, you'll need to implement every method of UITableViewDataSource and forward those messages to the original data source.
In your implementation of tableView:cellForRowAtIndexPath:, you'll be able to customize the cell returned by the original data source's implementation of that method.
Sounds like a lot of work just to change some fonts, doesn't it?