objective-c 开发最简单的UITableView时数据进不去的问题
今天在使用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时数据进不去的问题的更多相关文章
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...
- Windows在结构objective C开发环境
对于近期打算iPhone.iPod touch和iPad开发一些应用程序,所以.需要开始学习Objective C(苹果推出的类似C语言的开发语言).因为苹果的自我封闭的产业链发展模式(从芯片.机器. ...
- 如何开发一个简单的HTML5 Canvas 小游戏
原文:How to make a simple HTML5 Canvas game 想要快速上手HTML5 Canvas小游戏开发?下面通过一个例子来进行手把手教学.(如果你怀疑我的资历, A Wiz ...
- 重新想象 Windows 8 Store Apps (64) - 后台任务: 开发一个简单的后台任务
[源码下载] 重新想象 Windows 8 Store Apps (64) - 后台任务: 开发一个简单的后台任务 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后 ...
- IOS开发之表视图(UITableView)
IOS开发之表视图(UITableView)的基本介绍(一) (一):UITableView的基本概念 1.在IOS开发中,表视图的应用十分广泛和普及.因此掌握表视图的用法显得非常重要.一般情况下对于 ...
- Windows下搭建objective C开发环境
摘自:http://blog.csdn.net/zhanghefu/article/details/18320827 最近打算针对iPhone.iPod touch和iPad开发一些应用,所以,需要开 ...
- Python开发一个简单的BBS论坛
项目:开发一个简单的BBS论坛 需求: 整体参考“抽屉新热榜” + “虎嗅网” 实现不同论坛版块 帖子列表展示 帖子评论数.点赞数展示 在线用户展示 允许登录用户发贴.评论.点赞 允许上传文件 帖子可 ...
- 【HTML5游戏开发】简单的《找不同汉字版》,来考考你的眼力吧
一,准备工作 本次游戏开发需要用到lufylegend.js开源游戏引擎,版本我用的是1.5.2(现在最新的版本是1.6.0). 引擎下载的位置:http://lufylegend.googlecod ...
- .NET Web开发技术简单整理 转
.NET Web开发技术简单整理 原文:http://www.cnblogs.com/SanMaoSpace/p/3157293.html 在最初学习一些编程语言.一些编程技术的时候,做的更多的是如何 ...
随机推荐
- MeasureString 通过文本宽度获取绘制高度
using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using S ...
- MySQL5.5编译安装以及Debug
MySQL5.5以上版本安装是需要cmake 安装步骤: 设置编译参数cmake -DCMAKE_INSTALL_PREFIX='/data1/guosong/mysql_debug' -DDEF ...
- linux expect自动登陆远程服务器 批量管理服务器
#!/usr/bin/expect set ipaddress [lindex $argv 0] set passwd [lindex $argv 1] set timeout 3 spawn ssh ...
- bootstrap导航栏.nav与.navbar区别
刚刚看了bootstrap的导航栏,发现有点弄混了,现在来整理一下: 一.简单的ul,li组成的导航: <ul class="nav nav-pills justify-content ...
- JSON.parse()和JSON.stringify()和eval('(' + result + ')')
var str = '{"name":"huangxiaojian","age":"23"}' 结果: JSON.par ...
- linux下expect命令实现批量ssh免密
有时候我们需要批量发送ssh命令给服务器,但是有可能有些服务器是新加入的,还没有配置ssh免密,这个时候就会提示我们输入yes/no 或者password等,expect脚本命令就是用于在提示这些的时 ...
- Java学习笔记12---向上转型-父类的对象引用指向子类对象
当父类的对象引用没有指向父类的对象,而是指向了子类的对象时,调用方法或访问变量时会怎样呢? 假设父类为Person,子类为Student,有下面的两行定义: Student sTest = new S ...
- php垃圾回收
php所有的变量都存在一个zval的结构里面,通过refcount和is_ref来存储变量的引用关系.refcount是变量的引用次数,is_ref是变量是否被引用,当is_ref=0的时候refco ...
- 作为函数的mixin
作为函数的mixin 在一个 mixin 内部定义的变量或 mixin,都调用者可见,因此,它们可以作为它的返回值.如,以下Less代码: .count(@x, @y) { @sum:(@x ...
- DOM操作中,getElementByXXXX 和 querySelector 的区别
1. 返回值: getElements返回动态集合: 优: 首次查找效率高 缺: 可能造成反复查找DOM树 querySelector返回非动态集合: 优 ...