用三方做的豆瓣电影页面

代码如下:

//
//  RootViewController.m
//  UI__本地数据豆瓣电影
//
//  Created by dllo on 16/3/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RootViewController.h"
#include "Movie.h"
#import "Cinema.h"
#import "MovieTableViewCell.h"
#import "UIImageView+WebCache.h"
@interface RootViewController ()
<
    UITableViewDataSource,
    UITableViewDelegate
>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *movieArr;
@property (nonatomic, retain)NSMutableArray *cinemaArr;
@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor cyanColor];
    [self createData];
    [self createView];
   
}
- (void)createView {
    self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.rowHeight = 120;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
}
- (void)createData {
    //加载
    NSString *path = [[NSBundle mainBundle] pathForResource:@"movielist" ofType:@"txt"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    NSLog(@"%@", dict);
    // 加载影院数据
    NSString *cinemaPath = [[NSBundle mainBundle] pathForResource:@"cinemalist" ofType:@"txt"];
    NSData *cinameData = [NSData dataWithContentsOfFile:cinemaPath];
    NSDictionary *cinameDict = [NSJSONSerialization JSONObjectWithData:cinameData  options:0 error:nil];
    //  NSLog(@"%@", cinameDict);
    
    NSDictionary *cinameResult = cinameDict[@"result"];
    NSArray *cinameResultData = cinameResult[@"data"];
    NSLog(@"%@", cinameResultData);
    //  将电影数据存到model中
    NSArray *result = dict[@"result"];
    self.movieArr = [NSMutableArray array];
    for (NSDictionary *dict in result) {
        Movie *movie = [[Movie alloc]init];
        [movie setValuesForKeysWithDictionary:dict];
        [self.movieArr addObject:movie];
        [movie release];
    }
    //初始化self.cinameArr
    self.cinemaArr = [NSMutableArray array];
    //将影院数据存到model中
    for (NSDictionary *dict in cinameResultData) {
        Cinema *cinema = [[Cinema alloc]init];
        [cinema setValuesForKeysWithDictionary:dict];
        [self.cinemaArr addObject:cinema];
        [cinema release];
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.cinemaArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuse = @"reuse";
    MovieTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[[MovieTableViewCell alloc]initWithStyle:1 reuseIdentifier:reuse] autorelease];
    }
    //读取电影数据
    Movie *movie = self.movieArr[indexPath.row];
    cell.movieNameLabel.text = movie.movieName;
    //读取影院数据
    //Cinema *cinema = self.cinemaArr[indexPath.row];
    //cell.detailTextLabel.text = cinema.address;
   // cell.textLabel.text = cinema.cinemaName;
    //NSLog(@"%@", cinema.address);
    //
    [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:movie.pic_url]];
    return cell;
 
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
原文地址:https://www.cnblogs.com/mafeng/p/5289281.html