gpt4 book ai didi

iphone - 将 Plist 数据显示到 UItableview 中

转载 作者:行者123 更新时间:2023-11-29 04:14:29 26 4
gpt4 key购买 nike

我有一个包含字典和每个字典的字符串数量的 plist。请显示到下面的 url 中。plist 中的项目列表有数千个。

我需要将这些plist数据显示到UItableview中

eneter image.

如何做到这一点?

我的代码:

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

最佳答案

您已经超出了数组的末尾。

这可能是因为您已将每个部分的行数硬编码为 5。除非每个部分确实有 5 行,否则您应该在此处返回动态值。

关于iphone - 将 Plist 数据显示到 UItableview 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13912735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com