[英]Displaying Plist data into UItableview
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. 我有一个带有字典的plist和每个字典的字符串数。在下面的url中显示.plist中的项目列表以千为单位。
I need to display these plist data into the UItableview 我需要将这些plist数据显示到UItableview中
.
。
How to do this? 这个怎么做?
My Code: 我的代码:
- (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. 您已经耗尽了阵列的末端。
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. 可能是因为您已将每个节的行数硬编码为5。除非每个节中确实有5行,否则您应该在此处返回一个动态值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.