Other than tableView, what function type is used to scroll

So let’s just say I have a database item that has 100 properties. For any given record, what tool do I use to present the data and allowing the user to scroll through what is contained in each of those properties.

Would I use a TableView for that? if so, I guess I would have to get all of the properties into an array to feed the tableview?

Hi @linusb

You could load them all up is a vertical or horizontal CollectionView.


1 Like

If I understand you correctly you mean that the database has 100 records and each record has a number of properties.

The simplest way, in my view, is to use a tableView. The cell that is displayed on the screen would have minimal information and then in order to see further details of that record you can tap on the cell and present a Detail View Controller in which you can list as much detail as you need. You can even incorporate a ScrollView in the DetailView so that if there is more fields than will fit on the screen, you scroll down to see them all.

1 Like

No sorry. What I mean is that 1 record has an estimated 100 fields. And for each record, I want to have a detail screen where the user can scroll through all hundred of those fields and edit the values if so inclined.

Basically, each record will be that of a farm animal and I want the user to be able to see all of the data that is associated with that animal. 100 is just a round number I picked - it may not actually be 100 but it will be more than I can feasibly fit onto the screen at one time without scrolling. So I’m not sure If I use tableView to do that or collection view or some other display method I’m not yet aware of.

Yes you can use a tableView and clicking on a row you can go to another tableView that lists the properties.

You can use an array as your data source, and have custom animal objects for example pig, and pig could have 100 properties associated with it

1 Like

Ok, that sounds good. Currently I have the app working with a tableView that displays all my animals in list with just the animal name and the type of animal (and I have some filters that can be applied via icons at the top of the screen based upon animal type so you can limit the view to just one of the types).

My current setup is that when I click the row, it takes me to a modal view that I just have about 10 of the fields listed with textviews and the associated labels just stacked on top of each other.

So it sounds like I change that modal screen to incorporating a tableview and do like you say. Any guidance for how I feed those properties into an array?

If I have animal with properties:

and so on and so forth…

do I manually set up my array something like with all the fields…something like this?

animalArray = append[“animal.name”,“animal.dob”, “animal.type”, “animal.sex”]

…and then that array becomes the source for my tableview?

First yes change the modal view to be tableview instead.

To pass the properties you’ll feed the selected animal into your table view. (Rather than like you suggested of feeding each individual property)

This will make it so your data source is a single element in an array and each row, you can iterate through each property of your animal object.

To do this I believe you must have your animal object conform to a certain protocol (maybe case iterable) otherwise Swift doesn’t know how to use a for loop to go through the properties of the array.

1 Like

Ah right! I’m very new at all this so now this is clicking for me. So I would do something like inside my cellForRowAt at function:

for animalProperty in Animal {
let animalLabel = cell.viewWithTag(2) as? UILabel
animalLabel?.text = Animal.animalProperty[indexPath.row].name

or as I re-think this, I would probably set up the array in the viewdidload method… something like

 for property in Animal {
       animalArray.append [property]

and then the Animal.animalArray[indexPath.row] is what would feed my tableview…

I think that is it! :slight_smile:

1 Like

Yes setting up an array in viewDidLoad is that I was thinking as well, as another way to do it!!

(It’s programming, you can do everything a million ways!)

1 Like

Thank you for your help!

1 Like