• 用三方做的豆瓣电影页面


    代码如下:

    //
    //  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
  • 相关阅读:
    php总结4——数组的定义及函数、冒泡排序
    php总结3——基本函数、流程控制中的循环
    php总结2——php中的变量、数据类型及转换、运算符、流程控制中的分支结构
    php总结1 ——php简介、工作原理、运行环境、文件构成、语法结构、注释
    php中$t=date()函数参数意义及时间更改
    80端口未被占用,apache无法启动,命令行运行httpd.exe提示文档内容有错
    创建node.js一个简单的应用实例
    windows系统下nodejs、npm、express的下载和安装教程——2016.11.09
    前端工程师必备技能
    用于string对象中字符截取的几种函数总结——语法、参数意义及用途举例
  • 原文地址:https://www.cnblogs.com/mafeng/p/5289281.html
Copyright © 2020-2023  润新知