ViewController
#import "ViewController.h"
#import "Model.h"
#import "SecViewController.h"
@interface ViewController ()
{
NSMutableArray *data1;
UITableView *tab;
Model *_model;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
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{
returndata1.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 = [data1objectAtIndex: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];
returncell;
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
SecViewController *sec = [[SecViewController alloc] init];
NSDictionary*item = [data1objectAtIndex: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
#import
@interfaceSecViewController :UIViewController
@property(nonatomic,copy)NSString *img;
@property(nonatomic,copy)NSString *sd;
@end
SecViewController.m
#import "SecViewController.h"
@interface SecViewController ()
@end
@implementationSecViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title =_sd;
UIImageView*image = [[UIImageViewalloc]initWithFrame:CGRectMake(60,100,300,250)];
image.image= [UIImageimageNamed:_img];
[self.viewaddSubview:image];
// Do any additional setup after loading the view.
}
Model.h
#import
@interface Model : NSObject
@property(nonatomic,copy)NSString *title;
@property(nonatomic,copy)NSString *tatext;
@property(nonatomic,copy)NSString *image;
@end