Edit and add button for UITableView in ViewController - swift

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

Related

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/

Swift Add custom cell on button tap

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

How to make a combo box in iphone/ipad?

This is maybe a simple question, but I don't have a clue the keyword i had to search for this...
I want to create a simple selector (I called it spinner in Android). This is what i want to achieve
Or it will take a whole screen if it's in ipod touch / iphone.
So, I have 3 button that represent filter (category, country, sort) for a ListView... and if I press one of the button, a popover / dialog should be appear to select the filter for each button.
thanks...
Please let me know if I need to add some information to make the question clear.
Its not so much typical that is it appearing.
Create a new UIViewController class with xib and adjust view size you want to display for combo box or popviewControoler. Then put navigation controller over and tableviewController.
And customize your UIViewController using its controller class. Controller class will be reponsible for displaying and selecting data.
Now in your MainViewController From where you want to show ComboBox or popviewcontroller.
declare popViewController instance variable,synthesize it.
implement a userdefined method here alloc your popviewcontroller class and assign it to popviewController instance variable of your class.
Then called it didSelectRowAtIndexPath.
When popover dismiss you set popViewController result in instance variable of this class so it can easily access in MainViewController class.
You can achieve combo box like functionality by adding a UItableView in a UIView and implement all the delegates of UITableView in that custom view.
Now you can add object of that custom UIView where ever you want that combo. Just you have to workout with some Frame setting.

iOS Storyboard How to access the controls and add event handlers, and binding data to controls added on Storyboard

I used to create the UI thru code. But now I have to use storyboard. I am confused about how to add the event handlers to the controls added on the storyboard and how to bind the data dynamically to the controls added on storyboard. A sample scenario is An UIView is added on the storyboard and two UITableViews and a button are added on top of it. I want to add event handler to the button and bind data to the table views. How do I do this. If I subclass the UIView added on the storyboard will I have access to the controls(button, two table views) added on top of the view or how else I should achieve this ?. Please help !
Adding an event handler to a button is relatively simple. In your UIViewController subclass simply add a method similar to the one below, then in your interface builder select the viewcontroller and on the right side panel click the right most button at the top which looks like an arrow pointing to the right. under received actions drag the circle to the button that you want to perform the action.
-(IBAction)doSomething:(id)sender{
//code for doing what you want your button to do.
}
A separate way you could do it, if you still want to do it programatically is to do the same thing you're used to doing, except in your .h file add IBOutlet UIButton *buttonName; and in the right pane under outlets you'll see your button. which can then be referenced by name within the .m file.

iOS5 - how to use storyboard to transit from UITableViewController to another ViewController

Using Storyboard I want to transition from UITableViewController to another ViewController on the click of Detail Disclosure button. I created a proper segue, but the transition does not happen when I run the application. Creating a segue from UIButton to a ViewController works properly. I tried embedding Navigation Controller in UITableViewController, it did not help.
Look forward to somebody helping me with this, as I have already spent four days on it.
Thanks!
Here's the most complete example I have found. Most have fallen short by not providing an example of how to go from the list of records to the detail of the selected records.
http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007416-Intro-DontLinkElementID_2
and here's the link to part 2 of the above tutorial:
http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2
It should work without any code on your side
Ctrl click the prototype cell (table cell) and drag it to connect with the detail view. This will pop up a segue window. I chose Push since I have a navigation controller - but you can use Modal as well.
Note the segue name should show "Segue from UITableViewCell to ).
I've put in the disclosure icon on the Table cell as well.