-1

Is it possible to use a UITableView to be able to enter a value into a database's field.

For example, if I was to have a UITableView pointing to a field within a database and if I wanted to enter a new entry into the database - tap on the UITableView Cell that would then allow keyboard input into the cell which ultimately end up being a new record in the database??

Popeye
  • 10,831
  • 9
  • 52
  • 85
Fritzables
  • 257
  • 1
  • 4
  • 10

2 Answers2

1

This is possible, but if something is possible doesn't mean you should be doing so.

You might ask why?

Well! you are trying to input data from view directly to database, this is a very bad practice. There are many reason for it being bad, the major is efficiency and security reasons. You should consider using MVC pattern.

Now since its completely possible, I will explain the idea on how to do it and conclude with links that will have real code examples.

In tableView:cellForRowAtIndexPath: add a TextField with tag (to get the reference back in future) and add it to contentView of the cell and have it hidden.

Now in tableView:didSelectRowAtIndexPath: make the cells editing property to YES.

Then, in tableView:willBeginEditingRowAtIndexPath: get the reference to the textfield in contentview using viewWithTag: method and hide the textLabela and unhide the textfield.

In textfield's delegate textFieldDidEndEditing: make cell's editing property as no (yea, you need to keep the reference) unhide the textlabel and hide textfield.

In tableView:didEndEditingRowAtIndexPath: write methods which will commit the changes to your db.

Below are list of links which will get you code examples:

Having a UITextField in a UITableViewCell

Accessing UITextField in a custom UITableViewCell

iOS Database Tutorial

There are no examples for your requirement 'coz it bit bad way of doing things.

Community
  • 1
  • 1
egghese
  • 2,088
  • 15
  • 26
0

Yes its possible....

You can use delegate methods to take data form you cells textfield to your parent view controller and then save data in database.