0
我已经做了一个uitableview之前,但与最小的单元格。我想知道如何用100个以上的名字来填充表格,并且每个名称都有个别的详细视图。 此外,可搜索。谢谢。使用大量数据填充uitableview最简单的方法是什么?
注意:此数据是从网站复制并粘贴的。我目前在一个Excel文档中。
我已经做了一个uitableview之前,但与最小的单元格。我想知道如何用100个以上的名字来填充表格,并且每个名称都有个别的详细视图。 此外,可搜索。谢谢。使用大量数据填充uitableview最简单的方法是什么?
注意:此数据是从网站复制并粘贴的。我目前在一个Excel文档中。
最简单的是使从数据plist
文件有以下NSArray
和NSDictionary
格式:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Name 1</key>
<string>Description 1</string>
</dict>
<dict>
<key>Name 2</key>
<string>Description 2</string>
</dict>
</array>
</plist>
这个文件添加到应用程序。当你要访问它,你这样做是通过
NSString *path=[[NSBundle mainBundle] pathForResource:@"MyList" ofType:@"plist"];
NSArray *array =[NSArray arrayWithContentsOfFile:path];OfFile:path];
现在你有一个包含NSDictionaries
,各自有您需要为您UITableView
信息的NSArray
。
现在您只需要使用此数组填充UITableView
。通过实施这两种方法来实现这一点:
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Create your cells
NSDictionary *dict = [array objectAtIndex:indexPath.row];
// use the key and description however you like in your cell
}
非常感谢你 –