[英]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. 我正在尝试在UITableViewController上显示整行数据,而不是在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 name
在我的数据库中保存“ Name
列
address
holds the Address
column on my database address
在我的数据库中保存“ Address
列
latitude
holds the Latitude
column on my database latitude
在我的数据库中保存“ Latitude
列
below is my database table using phpmyadmin 下面是我使用phpmyadmin的数据库表
And by doing this, my tableview will look like this
通过这样做,我的表视图将如下所示
I want my tableview to display this
我希望我的表视图显示此
I'm not sure how to do this at all. 我完全不确定如何执行此操作。 Any help will be appreciated please, thank you!
任何帮助将不胜感激,谢谢!
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? 您为什么不将出队分配给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. 然后是第二个:您需要定义自己的UITableViewCell(也许在UIStoryboard中)并使用它创建类,以便可以定义单元格上需要的所有UILabel。
In case you did that already, then dequeue your UITableViewCell as what it is, not as UITableView. 如果您已经这样做了,那么请按原样将UITableViewCell出队,而不是将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. 如果要将所有字段都放在单独的单元格中,则应仅使用单元格的textLabel属性。
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. 您可以进行模运算,为每个对象分配一个部分,并确定该单元格中该属性的行的模数。
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. 1)将您的记录数乘以3。这就是您的总行数。 so if there are 5 records, 5x3=15 rows.
因此,如果有5条记录,则5x3 = 15行。 then in
cellforrowatindexpath
然后在
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. 2)将记录数作为段数。 and in each section take 3 rows.
并在每个部分中占据3行。 then in
cellforrowatindexpath
然后在
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]....
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. 几个月后,我回头看了一下,在获得了更多iOS开发经验之后,我想找到了解决问题的方法。
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. 我想如果我要将所有想要的信息放在
Apple
或google
,然后将其放在字典中并附加到数组中。
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. 我还没有尝试过,但是在做了一些Firebase开发之后,这就是我一直在做的事情,我认为这是相同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.