Tableview with picker view and persistence - uitableview

I´m struggling a lot to find a good solution, and searched a lot also, but i can´t find anything similar with what i want, so i hope anyone can help me:
I have two tableviews, in the first one i already have custom cells, and each cell has two textfields, one textfield for the product name, and the other one to it´s price, then if the user want´s, he can had more cells which he will insert more products with their respective price.
The second tableview has also two textfields, in the first textfield he will choose one product( inserted in the first tableview)with a pickerview, and when he chooses the product, i want the respective price to appear in the other texfield.
My question is, should i be using core data? or another type of persistence? and is it possible to assign the values of the texfields to the atributes created in a model of core data?

You can use core data for your requirement and you can assign the data to textfields.

Related

save data in array coming from 2 different uitableviews in ios swift

Recently i am facing an issue in saving data of Uitableview inside Uitableview cell in ios swift
Senario
Questions asked in above pictures is one table view and this table view cell contain 1 label for question text and uitableview that show possible answers provided by admin and user is allowed to select one.i am enable to display data perfectly but facing an issue when trying to save answers of every question in one array.it always store the value of last questions answers.
Why are you using two different UITableView? Any specific reason? You can get data from different resources but there is no need to use two table views.
You should use a section header view to show the questions & sections rows as options(answer option).
You can dynamically add or delete the options(rows) from any section(question). Also, there will not be the above scenario if you implement it using this easy approach.
Let me know in case of any query.

With IOS, is there a way of making a proper table with rows and columns?

I have been trying to find a way of creating a table, with rows and columns, for iOS. The UiTableView is basically a tree-structured list like this
Apple sample code, but because it's called a table view, it hijacks any attempt to search for a proper table.
There are a couple answers that suggest very clunky ways of doing it, like this SE Question, but it's quite old. Has the situation changed since this question was asked?
I've done this using UITableView by simply designing custom UITableViewCells that are segmented into columns. All the custom rows together certainly give the appearance of a multi-column table. When any of your data in a column or row updates, you re-render the tableView or have each row in charge of its own re-rendering (i.e. via an NSNotificationCenter message), and the whole experience for the user is as a multi-column table. If you setup your table's data as a separate row-column data model, it's pretty easy to get all the individual cells to go where they need to go with your custom UITableViewCell.
take a UITableView and on tableRow take 3 view of(width=1 and height=row height), each view ill be at equal distance from another one. and take label between these view at end it ill look like a table with rows and column

iOS Swift How to Extract Strings from All Selected Rows in a TableView

I want to loop through a TableView and extract the text from all the selected rows. I suppose I "could" create and maintain a special array that is updated every time a row is selected/deselected using the didSelect/didDeselectRowAtIndexPath methods. But creating a separate array seems like an extra step. Is there no way to let the TableView itself serve as the array and then simply loop through it and get the selected rows? What would the code look like? I'm new to Swift, so this might be a silly question.
Part of the problem is that cells are supposed to be reused, and when used this way it is not possible to loop through them all. You could get around this by using a unique reuse identifier for each cell, such as the indexPath itself or some underlying unique id in your model. Then, you could indeed loop through all cells and retrieve whatever state you desired from each.
You would, however, find your application crushed under the weight of too many cells being instantiated and kept in memory. If you don't have many cells you won't be killed, but try it with a big data set and your app will enjoy a very quick death.
It is far more efficient to store one array with a bunch of id's than a large number of memory-intensive UITableViewCells.
As mentioned in comments, you should work with underlying datasource, not the table itself.
For example if your table shows rows from Array, it is way more faster to retrieve strings directly from that array than creating UITableViewCells and get strings from them.
Get indices of selected rows using UITableView's property indexPathsForSelectedRows.
Query datasource for each row.
As has been said the tableview only handles displaying, your datasource is what powers the data shown if you think about it.
Plus as said before the tableview dequeues cells as they scroll on and off the screen.
The best way to achieve what you want is to add a property to your datasource for each element that will allow you to filter out the select properties easily.
How are you storing the state for each selected cell currently? As this is the same functionally you would use to be able to generate your selected text array.

Insert cells into a section of an already statically created table

I am creating an iOS app that has a form to create a certain 'event'. This form is wrapped in a tableview. This tableview consists of static cells. But there is one section in the table that can be used to add persons to this event and thus on a button press a new tableview cell needs to be inserted at that section. To demonstrate this see the following image:
What I want to know is how to insert cells into a static table. And also how to grab them when the user submits the form, since, as far as I'm concerned, you can't grab a specific section of a table.
I already looked at this kind of concept but this does not apply on adding cells:
Mixing static and dynamic sections in a grouped table view
Thanks,
I think there are (at least) 2 workarounds for this:
You could add a dynamic UITableView as a child to the UITableViewCell. See this stack overflow question about this.
An other solution would be to bypass the table functionality in that cell and change the height of the cell and add the extra controls manually.
It's not possible to add or remove cells at runtime, you'll need to use a data source for your tableview. I asked a similar question here, with no luck.
In response to your second question, you can always grab cells using the cellForRowAtIndexPath: method on UITableView.

"Compact" view in iOS

I have a view in iOS (iPhone) that have multiple components, organized in sort of a stack way (one in top of the next). Those are user account properties, some could be blank.
So, I have in my view the components layout like this:
UITextField1 (Name)
UITextField2 (Location)
UITextField3 (Age)
UITextView1 (Bio)
UITableView (user entries).
Some of the fields could be blank. Instead of having blank spaces for the blank fields I would like the next field to move upper.
This is like this question of flowlayout: What is the best/easiest way to create 'flow layout' type layout in iOS.
I can only see two ways of dealing with this:
Creating a function that traverse all the UIViews and determines which ones are blank and move the following upper.
Creating a UITableView and use different cell heights for cells whose content is empty.
Ideally there would be a component, but I cannot find it (basically some sort of stack/flow layout).
Anyways, I believe that I am going to implement the option #1 above, but I don't know if there is an "standard" way of accomplishing this (I honestly don't even know the proper term to look for this feature).
Thanks.
I would lean more in the direction of your second choice by using a UITableView but not the way you propose.
This would be my approach using a UITableView:
Create a UITableViewCell (or custom cell) for each one of my
components and assign a tag value to each, we'll use these later. You can do this in viewDidLoad.
Add code in numberOfRowsInSection to check to see which fields have
data values present. Return the total count of the number of fields
with data values
In cellForRowAtIndexPath again, check if data exists for that field
If so, check to see if the cell created in step one has already been created or not (if not, create)
If not, increment a counter of some sort to increase your tag value and find the next field that has a value. Once found, use that "tag/index" number to "return" the proper cell.
In the end, you have a UITableView only displaying the fields with data.

Resources