Xcode:tableview中的节存在问题
我是Xcode编码的初学者。 我想从plist和section获得一个tableview加载。 我的问题是在我的分区中正确放置行 在我的plist中,我在每个条目中都有我的节的名称,但我不知道如何获取这些信息。因此,我手动添加代码的名称,我的两个部分 我的plist看起来像这样:Xcode:tableview中的节存在问题,xcode,tableview,Xcode,Tableview,我是Xcode编码的初学者。 我想从plist和section获得一个tableview加载。 我的问题是在我的分区中正确放置行 在我的plist中,我在每个条目中都有我的节的名称,但我不知道如何获取这些信息。因此,我手动添加代码的名称,我的两个部分 我的plist看起来像这样: <dict> <key>Root</key> <array> <dict> <key>DE
<dict>
<key>Root</key>
<array>
<dict>
<key>DESCRIPTION</key>
<string>Robe ponctuée de petites tâches sombres plus ou moins rondes et pleines tel que l'on retrouve chez le guépard</string>
<key>TITLE</key>
<string>Spotted</string>
<key>IMAGE</key>
<string></string>
<key>MINI</key>
<string>spotted.png</string>
<key>CAT</key>
<string>MOTIFS</string>
</dict>
<dict>
<key>DESCRIPTION</key>
<string>Robe ponctuée de taches plutôt rondes offrant deux tons contrastants. Le centre de celles-ci se voulant plus clair et le pourtour plus sombre. On appelle rosette ouverte une tâche qui n'est pas totalement cerclée par le pourtour plus foncé et rappelant la forme d'un croissant de lune. </string>
<key>TITLE</key>
<string>Rosettes ouvertes ou demi-lunes</string>
<key>IMAGE</key>
<string></string>
<key>MINI</key>
<string>roset-ouv.png</string>
<key>CAT</key>
<string>MOTIFS</string>
</dict>
感谢您非常有用的帮助表视图数据源旨在为表视图提供信息。当需要显示这些值时,它会询问其数据源,有多少节,特定节中有多少行。返回节数的方法不是必需的,默认情况下将返回1。但这是一个很好的实践,可以始终实现它。 我可以从代码中的注释中理解,只有一个部分
// not required
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
// you said only one section
return 1;
}
因此,现在返回正确的节数,表视图需要知道每个节有多少行(即使只有一个节),这发生在:-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)节代码>,这是必需的方法
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
// return here the number of rows
// you have only one, don't check the section number...
return [self.tabWebSites count];
}
最后,数据源必须将每个单元格返回到表视图。我看到您在-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)节中进行了尝试
,将部分
与整数进行比较<代码>部分是nsindepath
的类型,不是int
或NSUInteger
,所以不能这样比较。相反,您可以分别使用以下命令检索节号和行号:
NSUInteger sectionNumber = [indexPath section];
NSUInteger rowNumber = [indexPath row];
然后使用这两个数字,您可以在数组中检索正确的对象,并设置单元格的内容
您将在苹果的中找到有用的信息。希望这能有所帮助。法国超级消费电子展评论!谢谢您的帮助,但是如何在数组中检索正确的对象呢?我不知道如何使用这两个数字因为您只有一个部分,您可能有一个包含数据的数组,只需在id myDataObject=[myArray objectAtIndex:[indexath row]]中选择值即可代码>。另外,如果我的答案符合您的需要,请不要忘记单击左侧的复选标记;)()
NSUInteger sectionNumber = [indexPath section];
NSUInteger rowNumber = [indexPath row];