当检索 XML 数据时,uitableview 的 numberOfRowsInSection 返回类型是什么?
我有一个名为
records
的NSMutableArray
和一个NSArray
。现在我正在使用
TBXML 解析器
检索 XML 属性及其值,并将属性值插入到NSArray
中。此
NSArray
是records
的对象。
当我想在表格视图单元格中显示 XML 数据的值时,numberofRowsInSection
是什么?
这是我的数据检索过程......
[records addObject:[NSArray arrayWithObjects:
[TBXML textForElement:id],
[TBXML textForElement:productNumber],
[TBXML textForElement:name],
[TBXML textForElement:availableStock],
[TBXML textForElement:image],
[TBXML textForElement:quantityOrderMin],
[TBXML textForElement:dateCreated],
[TBXML textForElement:dateUpdated],nil]];
我的 XML 数据是......
<ProductData HASH="21106941">
<id>1</id>
<productNumber>a91cc0f4c7</productNumber>
<name>Product 1</name>
<seoTitle>product-1</seoTitle>
<viewCount>0</viewCount>
<availableStock>100.0</availableStock>
<lowStock>0.0</lowStock>
<image>5e928bbae358c93caedf6115fa7d178b.jpg</image>
<quantityOrderMax>20.0</quantityOrderMax>
<dateCreated>2011-10-06T16:08:45</dateCreated>
</ProductData>
<ProductData HASH="409555632">
<id>2</id>
<productNumber>d8287e2e51</productNumber>
<name>Product 2</name>
<seoTitle>product-2</seoTitle>
<description>
<p>Lorem ipsum dolor sit amet, consectetue...</p>
</description>
<viewCount>0</viewCount>
<availableStock>100.0</availableStock>
<image>8bbd8dfff3cdd28285d07810a4fe7c32.jpg</image>
<quantityOrderMin>1.0</quantityOrderMin>
<dateCreated>2011-10-06T16:08:45</dateCreated>
</ProductData>
我能够检索 UITableviewCell
中的数据,但它显示 NSArray< 的前两个检索到的数据/code> 因为
records
数组中的行数为两行。但我想设置 numberOfRowsInsection 将根据 NSArray
检索到的属性值的总数。
我遇到了问题,并且我知道问题就在这里:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"The number of row in the object array: %d ",[records count]);
return [records count];
}
我该如何解决它?
I have a
NSMutableArray
named asrecords
and aNSArray
.Now I am retrieving an XML attribute and its value, using
TBXML parser
and inserting the attribute value in theNSArray
.This
NSArray
is an object ofrecords
.
What will be the numerberOfRowsInSection
when I want to display the value of XML data in tableview cell?
This is my data retrieving procedure....
[records addObject:[NSArray arrayWithObjects:
[TBXML textForElement:id],
[TBXML textForElement:productNumber],
[TBXML textForElement:name],
[TBXML textForElement:availableStock],
[TBXML textForElement:image],
[TBXML textForElement:quantityOrderMin],
[TBXML textForElement:dateCreated],
[TBXML textForElement:dateUpdated],nil]];
And my XML data are....
<ProductData HASH="21106941">
<id>1</id>
<productNumber>a91cc0f4c7</productNumber>
<name>Product 1</name>
<seoTitle>product-1</seoTitle>
<viewCount>0</viewCount>
<availableStock>100.0</availableStock>
<lowStock>0.0</lowStock>
<image>5e928bbae358c93caedf6115fa7d178b.jpg</image>
<quantityOrderMax>20.0</quantityOrderMax>
<dateCreated>2011-10-06T16:08:45</dateCreated>
</ProductData>
<ProductData HASH="409555632">
<id>2</id>
<productNumber>d8287e2e51</productNumber>
<name>Product 2</name>
<seoTitle>product-2</seoTitle>
<description>
<p>Lorem ipsum dolor sit amet, consectetue...</p>
</description>
<viewCount>0</viewCount>
<availableStock>100.0</availableStock>
<image>8bbd8dfff3cdd28285d07810a4fe7c32.jpg</image>
<quantityOrderMin>1.0</quantityOrderMin>
<dateCreated>2011-10-06T16:08:45</dateCreated>
</ProductData>
I am being able to retrieve data in UITableviewCell
, but it's displaying first two retrieved data of the NSArray
because the number of rows are two in records
array. but i want to set the numberOfRowsInsection will be according to the total number of attribute value retrieved by NSArray
.
I have got the problem and I know the problem is here:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"The number of row in the object array: %d ",[records count]);
return [records count];
}
How can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种方法可以解决这个问题。
正确的方法是查看这个 TBXML 教程 关于解析。这向您展示了如何解析每个
ProductData
元素条目中的每个属性。强力方法(这不是我会做的)是解析你的“记录”数组,如下所示:
通过这个快速枚举等等
There are two ways to approach this problem.
The right way would be to take a look at this TBXML tutorial regarding parsing. This shows you what to do to parse each of the attributes out of each
ProductData
element entry.The brute force method (which isn't one that I would do) would be to parse through your "records" array, which looks like this:
and so on via this fast enumeration