Iphone 将Plist填充到UITableView,存储在文档目录中

Iphone 将Plist填充到UITableView,存储在文档目录中,iphone,ios,uitableview,plist,nsdocumentdirectory,Iphone,Ios,Uitableview,Plist,Nsdocumentdirectory,我已将plist存储在文档目录中,如果它存储在文档目录中,如何调用UITableView . 这是我从普利斯特那里读到的 在ViewDidLoad - (void)viewDidLoad { NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDo

我已将plist存储在
文档目录中
,如果它存储在文档目录中,如何调用
UITableView

. 这是我从普利斯特那里读到的

ViewDidLoad

- (void)viewDidLoad {

 NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES); 
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentPlistPath = [documentsDirectory stringByAppendingPathComponent:@"p.plist"];

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:documentPlistPath];

NSArray *valueArray = [dict objectForKey:@"title"];

self.mySections = valueArray;

[super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//Return the number of sections.
return [self.mySections count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSString *key = [self.mySections objectAtIndex:section];
NSArray *dataInSection = [self.myData objectForKey:key];
return [dataInSection count];
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *key = [self.mySections objectAtIndex:section];
return [NSString stringWithFormat:@"%@", key];
}

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return self.mySections;
}


- (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];



NSString *key = [self.mySections objectAtIndex:section];

NSDictionary *dataForSection = [[self.myData objectForKey:key] objectAtIndex:0];
NSArray *array=dataForSection.allKeys;

cell.textLabel.text = [[dataForSection allKeys] objectAtIndex:row];    
cell.detailTextLabel.text=[dataForSection valueForKey:[array objectAtIndex:indexPath.row]];

return cell;
}
编辑 当i
NSlog
valueArray
输出为
({pass=tryrt;title=tyr;},
{pass=tryrt;title=tyr;},
{pass=tryrt;title=tyr;},{pass=tryrt546;title=tyr;})

这意味着问题出在我们身上


cellforrowatinexpath

您在.plist.ya.有一个字典数组。代码中需要做哪些更改。帮助此代码本身看起来不太好,它假设
self.myData
是字典(行)数组(节)的字典在
numberOfRowsInSection
中,但是要成为
NSString
cellforrowatinexpath
中数组字典的字典,这是非常混乱的。我认为,如果您先决定数据源结构,会更容易。如果要将给定的.plist读入
self.myData
并使用它,则不清楚该数据如何表示节和行。也许你可以解释一下什么是
pass
title
值。另外,如果需要,您可以更改.plist结构吗?就像我有两个文本框,用于存储在
pass
title
中的这些值。现在要从plist和ya填充,我可以更改,但需要更改以将数据存储到plistWell中,我可以想象
pass
值具有相同的成对
title
被分组到节中,因此
title
值被用作节标题,
pass
值是文本行。您想看到类似的内容吗?您在.plist.ya有一个字典数组。代码中需要做哪些更改。帮助此代码本身看起来不太好,它假定
self.myData
是字典(行)数组(节)的字典在
numberOfRowsInSection
中,但是要成为
NSString
cellforrowatinexpath
中数组字典的字典,这是非常混乱的。我认为,如果您先决定数据源结构,会更容易。如果要将给定的.plist读入
self.myData
并使用它,则不清楚该数据如何表示节和行。也许你可以解释一下什么是
pass
title
值。另外,如果需要,您可以更改.plist结构吗?就像我有两个文本框,用于存储在
pass
title
中的这些值。现在要从plist和ya填充,我可以更改,但需要更改以将数据存储到plistWell中,我可以想象
pass
值具有相同的成对
title
被分组到节中,因此
title
值被用作节标题,
pass
值是文本行。你想看这样的东西吗?谢谢!现在工作正常。但问题是…在tableview中…每个值显示两次..表示第1行和第2行中的每个人的重复值,如果我返回1;在numberofrowsinsection…中,现在输出为。。。那个问题是因为我不知道你到底想要什么…:)]谢谢!现在工作正常。但问题是…在tableview中…每个值显示两次..表示第1行和第2行中的每个人的重复值,如果我返回1;在numberofrowsinsection…中,现在输出为。。。这个问题是因为我不知道你到底想要什么……:)]
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//Return the number of sections.
return [self.mySections count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSArray *allKeys = [[self.mySections objectAtIndex:section] allKeys];
return [allKeys 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];
NSArray *allKeys = [[self.mySections objectAtIndex:section] allKeys];
cell.textLabel.text = [[self.mySections objectAtIndex:section] objectForKey:[allKeys objectAtIndex:0]];    
cell.detailTextLabel.text=[[self.mySections objectAtIndex:section] objectForKey:[allKeys objectAtIndex:1]];

return cell;
}