一,效果图。

二,,工程文件如下图所示:

三,DataModel.h


#import <Foundation/Foundation.h>
 
@interface DataModel : NSObject
{
    NSArray *myData;
}
-(NSString *)getNameAtIndex:(int)index;
-(int)getRowCount;
 
@end
 
 

DataModel.m


//数据库文件
#import "DataModel.h"
 
@implementation DataModel
 
-(id)init
{
    if (self=[super init]) {
        
        myData=[[NSArray alloc]initWithObjects:@"first",@"second",@"three",@"four", nil];
     }
    return self;
}
//显示数组中数据
-(NSString *)getNameAtIndex:(int)index
{
    return (NSString *)[myData objectAtIndex:index];
}
//显示行数
-(int)getRowCount
{
    return (int)[myData count];
}
@end
 

四,ViewController.h


#import <UIKit/UIKit.h>
#import "DataModel.h"
 
@interface ViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *myTableView;
    DataModel *model;
}
@end
 

ViewController.m


#import "ViewController.h"
 
@interface ViewController ()
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //初始化数据
    [self initData];
    //初始化界面
    [self addBackgroundView];
}
#pragma -mark -functions
//初始化数据
-(void)initData
{
     model=[[DataModel alloc]init];
}
//初始化界面
-(void)addBackgroundView
{
    myTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 100, 320, 300)];
    myTableView.dataSource=self;
    myTableView.delegate=self;
    [self.view addSubview:myTableView];
 
}
#pragma -mark -UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [model getRowCount];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier=@"Cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.textLabel.text=[NSString stringWithFormat:@"%@",[model getNameAtIndex:(int)indexPath.row]];
    return cell;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
@end
 

参考资料:《iOS数据库应用高级编程(第2版)》

【读书笔记】iOS-简单的数据驱动程序的更多相关文章

  1. 《利用python进行数据分析》读书笔记--第六章 数据加载、存储与文件格式

    http://www.cnblogs.com/batteryhp/p/5021858.html 输入输出一般分为下面几类:读取文本文件和其他更高效的磁盘存储格式,加载数据库中的数据.利用Web API ...

  2. 《SQL Server企业级平台管理实践》读书笔记——SQL Server中数据文件空间使用与管理

    1.表和索引存储结构 在SQL Server2005以前,一个表格是以一个B树或者一个堆(heap)存放的.每个B树或者堆,在sysindexes里面都有一条记录相对应.SQL Server2005以 ...

  3. [读书笔记]iOS 7 UI设计 对比度

    好久没写随笔了,最近在读<iOS 7 byTutorials>,很不错,推荐给大家. 每一个好的程序员也都是一个设计师,不懂设计的程序员不是好的CTO.哈哈,开个小玩笑. iOS 7设计的 ...

  4. $《第一行代码:Android》读书笔记——第6章 数据持久化

    主要讲述了Android数据持久化的三种方式:文件存储.SharedPreference存储.SQLite数据库存储. (一)文件存储 其实Android中文件存储方式和Java的文件操作类似,就是用 ...

  5. 《利用python进行数据分析》读书笔记--第七章 数据规整化:清理、转换、合并、重塑(三)

    http://www.cnblogs.com/batteryhp/p/5046433.html 5.示例:usda食品数据库 下面是一个具体的例子,书中最重要的就是例子. #-*- encoding: ...

  6. 《统计推断(Statistical Inference)》读书笔记——第6章 数据简化原理

    在外行眼里统计学家经常做的一件事就是把一大堆杂七杂八的数据放在一起,算出几个莫名其妙的数字,然后再通过这些数字推理出貌似很靠谱的结论,简直就像是炼金术士用“贤者之石”把一堆石头炼成了金矿.第六章,应该 ...

  7. 深入理解linux网络技术内幕读书笔记(九)--中断与网络驱动程序

    Table of Contents 1 接收到帧时通知驱动程序 1.1 轮询 1.2 中断 2 中断处理程序 3 抢占功能 4 下半部函数 4.1 内核2.4版本以后的下半部函数: 引入软IRQ 5 ...

  8. OCA读书笔记(10) - 管理UNDO数据

    Undo自动管理与手动管理 undo段自动管理SQL> show parameter undo_management 将undo段改为手工管理SQL> alter system set u ...

  9. 读书笔记6pandas简单使用

    一.序列Series,很像numpy中的array数组,可以由列表.元组.字典.numpy中的array来初始化 >>> from pandas import Series > ...

  10. MySQL必知必会 读书笔记三:检索数据和数据排序

    检索数据 SELECT语句 它的用途是从一个或多个表中检索信息. 为了使用SELECT检索表数据,必须至少给出两条信息--想选择什 么,以及从什么地方选择. 检索单个列 SELECT col_1 FR ...

随机推荐

  1. spark 编译

    http://blog.csdn.net/zyj8170/article/details/44678405

  2. 【解决方案】HTTP could not register URL http://+:6001/

    Failed to host the DeployerNotificationReceiverSystem.ServiceModel.AddressAccessDeniedException: HTT ...

  3. AC_Dream 1216 G - Beautiful People

    题意:有n个人每人有一个力气值Si,美丽值Bi,满足Bi>Bj&&Si>Sj 或者 Bi<Bj&&Si<Sj 的人可以一起参见晚会,问最多有多少 ...

  4. 将XmlDocument转换成XDocument

    XmlDocument xml=new XmlDocument(); xml.LoadXml(strXmlText); XmlReader xr=new XmlNodeReader(xml); XDo ...

  5. Reinforcement Learning

    Q-learning 高潮博文 http://mnemstudio.org/path-finding-q-learning-tutorial.htm 模式识别与机器学习的区别. http://www. ...

  6. 解决debian中脚本无法使用source的问题

    #!/bin/sh source scripts/common.sh 现象: shell脚本中source aaa.sh时提示 source: not found 原因: ls -l `which s ...

  7. vuejs入门小demo-搜索大全

    这个demo非常适合入门的同学,不再是简单的todolist.用到的知识点有组件通信,过渡效果,vue-rsource,还有一些基本的vue指令. 先放一张截图: 是不是感觉高端大气上档次呢,演示地址 ...

  8. 终极事务处理(XTP,Hekaton)——万能大招?

    在SQL Server 2014里,微软引入了终极事务处理(Extreme Transaction Processing),即大家熟知的Hekaton.我在网上围观了一些文档,写这篇文章,希望可以让大 ...

  9. API Design

    REST API Design Guidelines V 1.0.201208 Draft 5 Last Updated: 08/31/2012 1       简介 本文档旨在规范REST API的 ...

  10. 2016校招内推 -- 腾讯SNG前端 -- 面试经历

    也是让某湿兄帮忙内推,然后过了四五天,电话打来了 一面: 1.首先是简单的自我介绍 2.你觉得一个前端工程师应该具备什么技能 比如用户体验这个方面他就贵问你具体的例子 3.让你设计一个web站点,假如 ...