Cyril
Cyril

Reputation: 2818

How to display a ROW of data from phpMyAdmin on iOS UITableViewController

I am trying to display a whole row of data on a UITableViewController RATHER than displaying a whole column of data on a UITableViewController.

Here is the kind of code I have which displays the COLUMN of data on a tableview

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    Location *object;
    object = [locationArray objectAtIndex:indexPath.row];
    cell.nameLabel.text = object.name;
    cell.descriptionLabel.text = object.address;
    cell.publisherLabel.text = object.latitude;
    return cell;
}

name holds the Name column on my database

address holds the Address column on my database

latitude holds the Latitude column on my database

below is my database table using phpmyadmin enter image description here

And by doing this, my tableview will look like this

enter image description here

I want my tableview to display this

enter image description here

I'm not sure how to do this at all. Any help will be appreciated please, thank you!

Upvotes: 0

Views: 91

Answers (3)

Cyril
Cyril

Reputation: 2818

I'm looking back at this a few months later and after gaining more experience in iOS development, I think I found the solution to my problem.

I think if I were to put all the information I want under Apple or google and such then put it in a dictionary and append it to an array.

I have not yet tried this but after doing some Firebase dev, that's what I've been doing and I think it would be the same for this.

Upvotes: 0

choli
choli

Reputation: 322

I would like to comment, but not enough reputation...

So first:

UITableView *cell = [tableView dequeueReusable....

Why don't you assign your dequeue to an UITableViewCell?

Then second: You'll need to define your own UITableViewCell (maybe in your UIStoryboard) and create the classes with it, so you can define all the UILabels you'll need on your cell.

In case you did that already, then dequeue your UITableViewCell as what it is, not as UITableView.

And third: Make sure your objects are set correctly, else obviously you won't get the right fields

Edit

If you want all fields in separate cells, then you should only use the textLabel attribute of a cell.

You could work with a modulo operation, having a section for each object and deciding on the modulo of the row which attribute is in this cell.

Upvotes: 1

JOA80
JOA80

Reputation: 527

Sorry the formatting didn't work, see below
The two ways of doing it.
1) multiple your number of records by 3. That would be your total number of rows. so if there are 5 records, 5x3=15 rows. then in cellforrowatindexpath

row 0 - name[0],  
row 1 - Address[0],  
row 2 - latitude[0],  
row 3 - name[1]....  

2) take number of records as number of sections. and in each section take 3 rows. then in cellforrowatindexpath

row 0 section 0 - name[0],  
row 1 section 0 - Address[0],  
row 2 section 0 - latitude[0],  
row 0 section 1 - name[1]....

Upvotes: 1

Related Questions