今天在使用UITableView时遇到的问题,我在plist文件配置的数据进不去列表,以下是解决方案

问题原因:plist文件root的type配置错误

如上图所示,博主是使用plist文件作为我的沙盒,if Root's Type 为array时

 self.simpleData = [[NSArray alloc] initWithContentsOfFile:filePath];

 self.simpleData=[NSArray arrayWithContentsOfFile:filePath];

上面的第一行与第三行代码任选其一就可以

如果type为Dictionary时

 NSMutableDictionary *data = [[NSMutableDictionary alloc]
                                initWithContentsOfFile:filePath];

利用这种方式将plist文件位置传进去就行。

附带源码

//
//  ViewController.h
//  Table
//
//  Created by snow on 2017/12/25.
//  Copyright © 2017年 snow. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UITableViewController

@property (strong,nonatomic)NSArray *simpleData;

@end
//
//  ViewController.m
//  Table
//
//  Created by snow on 2017/12/25.
//  Copyright © 2017年 snow. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"simpleData" ofType:@"plist"];
    //self.simpleDatas=[NSMutableArray arrayWithContentsOfFile:filePath];

    self.simpleData = [[NSArray alloc] initWithContentsOfFile:filePath];
 //  self.simpleData=[NSArray arrayWithContentsOfFile:filePath];
//    NSMutableDictionary *data = [[NSMutableDictionary
//                                  alloc]
//                                 initWithContentsOfFile:filePath];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.simpleData count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *identifierString = @"simpleTableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierString];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierString];
    }
    NSInteger rowIndex = [indexPath row];
    NSDictionary *cellDictionary = [self.simpleData objectAtIndex:rowIndex];
    cell.textLabel.text = [cellDictionary objectForKey:@"name"];
    cell.imageView.image = [UIImage imageNamed:[cellDictionary objectForKey:@"cover"]];

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    return cell;
}

@end

objective-c 开发最简单的UITableView时数据进不去的问题的更多相关文章

  1. iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)

    iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...

  2. Windows在结构objective C开发环境

    对于近期打算iPhone.iPod touch和iPad开发一些应用程序,所以.需要开始学习Objective C(苹果推出的类似C语言的开发语言).因为苹果的自我封闭的产业链发展模式(从芯片.机器. ...

  3. 如何开发一个简单的HTML5 Canvas 小游戏

    原文:How to make a simple HTML5 Canvas game 想要快速上手HTML5 Canvas小游戏开发?下面通过一个例子来进行手把手教学.(如果你怀疑我的资历, A Wiz ...

  4. 重新想象 Windows 8 Store Apps (64) - 后台任务: 开发一个简单的后台任务

    [源码下载] 重新想象 Windows 8 Store Apps (64) - 后台任务: 开发一个简单的后台任务 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后 ...

  5. IOS开发之表视图(UITableView)

    IOS开发之表视图(UITableView)的基本介绍(一) (一):UITableView的基本概念 1.在IOS开发中,表视图的应用十分广泛和普及.因此掌握表视图的用法显得非常重要.一般情况下对于 ...

  6. Windows下搭建objective C开发环境

    摘自:http://blog.csdn.net/zhanghefu/article/details/18320827 最近打算针对iPhone.iPod touch和iPad开发一些应用,所以,需要开 ...

  7. Python开发一个简单的BBS论坛

    项目:开发一个简单的BBS论坛 需求: 整体参考“抽屉新热榜” + “虎嗅网” 实现不同论坛版块 帖子列表展示 帖子评论数.点赞数展示 在线用户展示 允许登录用户发贴.评论.点赞 允许上传文件 帖子可 ...

  8. 【HTML5游戏开发】简单的《找不同汉字版》,来考考你的眼力吧

    一,准备工作 本次游戏开发需要用到lufylegend.js开源游戏引擎,版本我用的是1.5.2(现在最新的版本是1.6.0). 引擎下载的位置:http://lufylegend.googlecod ...

  9. .NET Web开发技术简单整理 转

    .NET Web开发技术简单整理 原文:http://www.cnblogs.com/SanMaoSpace/p/3157293.html 在最初学习一些编程语言.一些编程技术的时候,做的更多的是如何 ...

随机推荐

  1. 特征提取算法的综合实验(多种角度比较sift/surf/brisk/orb/akze)

    一.基本概念: 作用:特征点提取在"目标识别.图像拼接.运动跟踪.图像检索.自动定位"等研究中起着重要作用: 主要算法: •FAST ,Machine Learning forHi ...

  2. pwnable.kr login之write up

    main函数如下: auth函数如下: 程序的流程如下: 输入Authenticate值,并base64解码,将解码的值代入md5_auth函数中 mad5_auth()生成其MD5值并与f87cd6 ...

  3. JS中encodeURI,escape,encodeURIComponent区别

    js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1 ...

  4. windows服务器下iis的性能优化 服务器

    IIS性能优化 1.调整IIS高速缓存 HKEY_LOCAL_MACHINE SystemCurrentControlSetServicesInetInfoParametersMemoryCacheS ...

  5. MySQL相关的书籍

    http://item.jd.com/11389754.htmlhttp://item.jd.com/11390423.html http://item.jd.com/11398721.html

  6. 2017-11-22 Intall Ubuntu Log

    重启之后进入不了系统,安装工具check defect也不好用(问题尚不清楚),决定重做系统 直接用u盘(Universal_USB_Installer制作的安装工具,之前用都没有问题)安装,前面一起 ...

  7. webpack中tree-shaking技术介绍

    之前介绍过webpack3的新特性,里面提到webpack2支持了ES6的import和export,不需要将ES6的模块先转成CommonJS模块,然后再进行打包处理.正基于此,webpack2引入 ...

  8. react native android6+拍照闪退或重启的解决方案

    前言 android 6+权限使用的时候需要动态申请,那么在使用rn的时候要怎么处理拍照权限问题呢?本文提供的是一揽子rn操作相册.拍照的解决方案,请看正文的提高班部分. 解决步骤 1.Android ...

  9. input type="radio" 赋值问题

    之前项目中 后台传值 然后赋给单选input   在网上找了好久,现在有时间了,整理一下  ,方便以后有人会用到. $('radio[name="sex"][value'" ...

  10. 我的第一个python web开发框架(17)——产品管理

    这是后台管理系统最后一个功能,产品管理,它的接口与页面功能与上一章差不多. 获取产品列表接口 @get('/api/product/') def callback(): ""&qu ...