本文介绍了将Plist数据显示到UItableview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带字典的plist和每个字典的字符串数量。显示在下面的url中。这个项目列表在plist中有数千个。
I have a plist with Dictionary and numbers of strings per dictionary.show into the url below.and this list of items is in thousands in the plist.
I需要将这些plist数据显示在UItableview中
I need to display these plist data into the UItableview
。
怎么做?
我的代码:
- (void)viewWillAppear:(BOOL)animated
{
// get paths from root direcory
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentPlistPath = [documentsDirectory stringByAppendingPathComponent:@"p.plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:documentPlistPath];
valueArray = [dict objectForKey:@"title"];
self.mySections=[valueArray copy];
NSLog(@"value array %@",self.mySections);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.mySections count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *key = [[self.mySections objectAtIndex:section]objectForKey:@"pass"];
return [NSString stringWithFormat:@"%@", key];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.mySections count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
cell.textLabel.text = [[self.mySections objectAtIndex:row] objectForKey:@"title"];
cell.detailTextLabel.text=[[self.mySections objectAtIndex:section] objectForKey:[allKeys objectAtIndex:1]];
return cell;
}
推荐答案
你已经跑掉了数组结束。
You've run off the end of your array.
这可能是因为你已经将每个部分的行数硬编码为5.除非每个部分确实有5行,否则你应该在这里返回一个动态值。
It's probably because you've hardcoded the number of rows for each section to be 5. Unless there really are 5 rows in each section, you should be returning a dynamic value here.
这篇关于将Plist数据显示到UItableview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!