iphone - 将 Plist 数据显示到 UItableview 中

标签 iphone ios uitableview plist

我有一个包含字典和每个字典的字符串数量的 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/

相关文章:

ios - 是否可以控制 iOS 系统均衡器(这样我就可以影响其他应用程序播放的音频)

ios - UITapGestureRecognizer 将仅注册 >1 次点击

ios - UITableView - 在滚动时它会丢失与选定单元格关联的属性。如何保存这些属性? - swift

iphone - 使用 NSDictionary 'initWithContentsOfURL' 代替 Reachability.h

iphone - NSNumber 与 Int

iphone - 我如何在 cocoa/objective-c 中获取触摸的位置?

ios - 从 iOS 中的代码创建 localized.strings

android - Flutter - 如何将数据从网站解析为 ListView

ios - 快速滚动ios时自定义单元格中的UITextField值出现问题

swift - Swift 中的 UILabel 根据行数而变化