创建SecViewController 继UIviewcontroller
Model 继承nsobjec
AppDelegate.M中
导入
#import "ViewController.h"
然后
ViewController *vc = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nav;
return YES;
在ViewController.m中
导入Model.h 和SecViewController.h 遵守协议UITableViewDelegate和UITableViewDatasource
{
NSMutableArray *data1;
UITableView *tab;
Model *_model;
}
self.title = @"车型";
self.view.backgroundColor = [UIColor whiteColor];
NSString *filepath = [[NSBundle mainBundle]pathForResource:@"Property List" ofType:@".plist"];
data1 = [[NSMutableArray alloc]initWithContentsOfFile:filepath];
tab = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
tab.rowHeight = 60;
tab.dataSource = self;
tab.delegate = self;
[self.view addSubview:tab];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return data1.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@""];
}
_model = [[Model alloc] init];
NSDictionary *item = [data1 objectAtIndex:indexPath.row];
_model.title = [item objectForKey:@"title"];
_model.tatext = [item objectForKey:@"tatext"];
_model.image = [item objectForKey:@"image"];
cell.textLabel.text = _model.title;
cell.detailTextLabel.text = _model.tatext;
cell.imageView.image = [UIImage imageNamed:_model.image];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
SecViewController *sec = [[SecViewController alloc] init];
NSDictionary *item = [data1 objectAtIndex:indexPath.row];
_model.title = [item objectForKey:@"title"];
_model.image = [item objectForKey:@"image"];
sec.sd = _model.title;
sec.img = _model.image;
[self.navigationController pushViewController:sec animated:YES];
}
SecViewController.h中
@property(nonatomic,copy)NSString *img;
@property(nonatomic,copy)NSString *sd;
.m中
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title =_sd;
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 300, 250)];
image.image = [UIImage imageNamed:_img];
Model.h中
@property(nonatomic,copy)NSString *title;
@property(nonatomic,copy)NSString *tatext;
@property(nonatomic,copy)NSString *image;
自己弄plist