model传值
来源:互联网 发布:google地球 类似软件 编辑:程序博客网 时间:2024/06/05 02:10
1.Student.h
#import <Foundation/Foundation.h>@interface Student : NSObject@property(nonatomic,copy)NSString *name;@property(nonatomic,copy)NSString *hobby;@property(nonatomic,copy)NSString *address;@property(nonatomic,copy)NSString *phone;@property(nonatomic,copy)NSString *sex;@property(nonatomic,copy)NSString *age;@end
2.Student.m
#import "Student.h"@implementation Student//这个方法是KVC里负责纠错的方法,只要Key和属性名没有对应上,就会执行这个方法-(void)setValue:(id)value forUndefinedKey:(NSString *)key{}@end
3.RootViewController.m
#import "RootViewController.h"#import "Student.h"#import "Movie.h"@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>//定义model属性@property(nonatomic,retain)NSMutableArray *modelArr;@property(nonatomic,retain)NSMutableArray *movieArr;@end@implementation RootViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor=[UIColor cyanColor]; UITableView *tableView=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; [self.view addSubview:tableView]; tableView.delegate=self; tableView.dataSource=self; [self createMovie];}-(void)createMovie{ NSString *path=@"/Users/dllo/Desktop/UI/UI10_KVC/UI10_KVC/movielist.txt"; NSData *data=[NSData dataWithContentsOfFile:path]; NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; NSArray *movieArr=dic[@"result"]; self.modelArr=[NSMutableArray array]; for (NSDictionary *dic in movieArr) { Movie *movie=[[Movie alloc] init]; [movie setValuesForKeysWithDictionary:dic]; [self.modelArr addObject:movie]; [movie release]; }}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.modelArr.count;}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *reuse=@"reuse"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease]; } Student *stu=self.modelArr[indexPath.row]; cell.textLabel.text=stu.name; return cell;}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}-(void)cresteData{ NSString *path=[[NSBundle mainBundle] pathForResource:@"Student" ofType:@"plist"]; NSMutableArray *arr=[NSMutableArray arrayWithContentsOfFile:path]; NSLog(@"%@",arr); self.modelArr=[NSMutableArray array]; for (NSDictionary *dic in arr) { Student *stu=[[Student alloc] init]; [stu setValuesForKeysWithDictionary:dic]; NSLog(@"%@",stu.name); [self.modelArr addObject:stu]; [stu release]; }}
0 0
- model传值
- Model?
- Model
- model
- model
- Model
- model
- Model
- model
- Model
- model
- model
- Model
- model
- Model
- model
- Generative model & discriminative model
- model与Model
- thinkphp3.2整合银联手机网页支付
- [leetcode] 237. Delete Node in a Linked List 解题报告
- LeetCode Spiral Matrix II
- 堆栈,堆栈,堆和栈的区别
- Android混淆、反编译基础教程
- model传值
- printf()函数常用格式控制
- WKWebView显示空白页bug
- MUI如何有效的在浏览器中进行调试
- 150,项目管理器git的使用
- 对STL的一些小计
- PtSetResource() 导致 Memory fault 的原因分析
- 扣丁学堂——文件管理
- 有n个整数,指定位置m处插入g个值(用指针和函数)