用三方做的豆瓣电影页面

Posted ⬆️小马哥⬆️

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用三方做的豆瓣电影页面相关的知识,希望对你有一定的参考价值。

技术分享

代码如下:

//
//  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

 

以上是关于用三方做的豆瓣电影页面的主要内容,如果未能解决你的问题,请参考以下文章

团队-爬取豆瓣电影TOP250-需求分析

团队-Python 爬取豆瓣电影top250-需求分析

《团队-爬取豆瓣电影TOP250-设计文档》

豆瓣电影top250(网络爬虫)

简单团队-爬取豆瓣电影T250-项目进度

Java豆瓣电影爬虫——抓取电影详情和电影短评数据