【读书笔记】iOS-简单的数据驱动程序
来源:互联网 发布:少爷的喜欢lofter乐乎 编辑:程序博客网 时间:2024/05/14 11:53
一,效果图。
二,,工程文件如下图所示:
三,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-简单的数据驱动程序
- 《TQ2440的简单内存数据读写驱动程序》
- 驱动程序的同步处理-读书笔记
- 最简单的驱动程序
- 简单的字符驱动程序
- 最简单的Windows驱动程序
- 简单的字符设备驱动程序
- 一个简单的字符驱动程序
- TQ2440简单的按键驱动程序
- 一个简单的WDM驱动程序
- 一个简单的字符驱动程序
- 最简单的 Linux 驱动程序
- 【读书笔记】iOS-数据交换格式
- 各个数据的驱动程序汇总
- iOS简单的数据持久化
- iOS开发简单高效的数据存储
- iOS开发简单高效的数据存储
- 《简单的逻辑学》读书笔记
- 皮肤检测及对检测到皮肤单独校色 (基于自动白平衡)
- OnCreate&&OnInitDialog、Onclose&&OnDestroy
- 搜狗新人流程规范
- linux下pip安装mysql-python的错误解决方法
- 正则表达式识别ip
- 【读书笔记】iOS-简单的数据驱动程序
- linux系统进程的内存布局
- Ugly Number II
- linux下core文件设置与查看
- BufferedInputStream学习笔记
- 自定义dialogfragment全屏
- 【STL容器学习】-关联容器与map的使用方法
- STL学习----入门(1)[set]
- mysql语句错误(更新中)