项目描述:家常菜、川菜 、鲁菜、东北菜、甜品等各大菜系应有尽有,详细的制作步骤,再也不用为自己不会做饭而烦恼。

主要技术:主界面采用UISplitViewController的结构设计;自定义各大菜系的菜品展示界面cell;分别实现了用通知和代理传值;使用SDWebImage异步下载菜品图片并进行内存和硬盘缓存;使用WebView加载html菜品详细制作步骤;iPad 和 iPhone 的适配。

#import "MasterController.h"

#import "NSObject+CZ.h"

#import "CZFoodType.h"

#import "CZDetailController.h"

@interface CZMasterController ()

@property (nonatomic ,strong) NSArray *foodTypes;

@property (nonatomic ,strong) CZFoodType *foodType;

@property (nonatomic ,strong) NSIndexPath  *indexPath;

@end

@implementation CZMasterController

- (NSArray *)foodTypes

{

if (_foodTypes == nil) {

_foodTypes = [CZFoodType  objcWithFileName:@"food_types.plist"];

}

return _foodTypes;

}

//1.加载了数据

- (void)viewDidLoad {

[super viewDidLoad];

//设置初始值

self.foodType = self.foodTypes[0];

self.title = @"菜系";

}

- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

//先进行设备判断

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {//ipad

//选中当前显现的这一行

if (self.indexPath == nil) {

self.indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

//默认选中第一行

[self.tableView selectRowAtIndexPath:self.indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];

}else{

[self.tableView selectRowAtIndexPath:self.indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];

}

}

}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

#warning Incomplete implementation, return the number of rows

return self.foodTypes.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"foodType"];

if (cell == nil) {

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"foodType"];

}

CZFoodType *foodType = self.foodTypes[indexPath.row];

cell.textLabel.text = foodType.name;

cell.textLabel.textColor = [UIColor blueColor];

cell.textLabel.textAlignment = NSTextAlignmentCenter;

return cell;

}

//进行传值

//通知

//代理 两者存在关系  两者同时存在的地方  一者为另一者得代理

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

//获取当前模型

CZFoodType *foodType = self.foodTypes[indexPath.row];

//先进行设备判断

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {//ipad

//先判断是否为同一个模型

if (foodType == self.foodType) {

return;

}

//通知传值

//    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeFoods" object:

//     foodType];

//代理传值

if ([self.delegate respondsToSelector:@selector(masterController:andFoodType:)]) {

[self.delegate masterController:self andFoodType:foodType];

}

//赋值

self.foodType = foodType;

self.indexPath = indexPath;

}

//////iphone

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {//iphone

CZDetailController *vc = [[CZDetailController alloc]init];

vc.foodType = foodType;

[self.navigationController pushViewController:vc animated:YES];

}

NSLog(@"12345678");

}

@end

#import "DetailController.h"

#import "NSObject+CZ.h"

#import "Food.h"

#import "UIImageView+WebCache.h"

#import "CZCell.h"

#import "FoodType.h"

#import "MasterController.h"

#import "ComposeController.h"

@interface DetailController ()<MasterControllerDelegate,UISplitViewControllerDelegate>

@property (nonatomic ,strong) NSArray *foods;

@end

@implementation DetailController

//懒加载

- (NSArray *)foods

{

if (_foods == nil) {

_foods = [CZFood  objcWithFileName:@"type_1_foods.plist"];

}

return _foods;

}

- (void)viewDidLoad {

[super viewDidLoad];

//设置行高

self.tableView.rowHeight = 100;

//添加通知

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeFoods:) name:@"changeFoods" object:nil];

//设置标题

self.title = @"家常菜";

//自动调用代理方法

[self splitViewController:self.splitViewController willChangeToDisplayMode:self.splitViewController.displayMode];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

#warning Incomplete implementation, return the number of rows

return self.foods.count;

}

//存在问题:图片变大

//解决方法  自定义 cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

CZCell *cell = [CZCell cellWithTableView:tableView];

Food *food = self.foods[indexPath.row];

cell.food = food;

UIView *view1 = [[UIView alloc]init];

view1.backgroundColor = [UIColor greenColor];

cell.selectedBackgroundView = view1;

return cell;

}

//接收到通知会来到此方法

- (void)changeFoods:(NSNotification *)not

{

NSLog(@"%@",not);

CZFoodType *foodType = not.object;

//加载对应的 plist  字典转模型  放在数组里面

NSString *path = [NSString stringWithFormat:@"type_%@_foods.plist",foodType.idstr];

_foods = [CZFood objcWithFileName:path];

//设置标题

self.title = foodType.name;

//刷新列表

[self.tableView reloadData];

//自动滚到第一行

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

}

#pragma mark   CZMasterControllerDelegate

- (void)masterController:(CZMasterController *)vc andFoodType:(CZFoodType *)foodType

{

//加载对应的 plist  字典转模型  放在数组里面

NSString *path = [NSString stringWithFormat:@"type_%@_foods.plist",foodType.idstr];

_foods = [CZFood objcWithFileName:path];

//设置标题

self.title = foodType.name;

//刷新列表

[self.tableView reloadData];

//自动滚到第一行

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

}

//#pragma mark UISplitViewControllerDlegate

- (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode

{

//判断当前的显示样式

/*

UISplitViewControllerDisplayModeAutomatic,

UISplitViewControllerDisplayModePrimaryHidden,

UISplitViewControllerDisplayModeAllVisible,

UISplitViewControllerDisplayModePrimaryOverlay,

*/

if (displayMode == UISplitViewControllerDisplayModePrimaryHidden ) {//主要的隐藏

//        svc.displayModeButtonItem.title = @"菜系";

self.navigationItem.leftBarButtonItem = svc.displayModeButtonItem;

}

if (displayMode == UISplitViewControllerDisplayModeAllVisible) {//全部显示

self.navigationItem.leftBarButtonItem = nil;

}

}

//- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc

//{

//

//    barButtonItem.title = @"菜系";

//

//    self.navigationItem.leftBarButtonItem = barButtonItem;

//}

//

//- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem{

//

//

//

//    self.navigationItem.leftBarButtonItem = nil;

//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

//0.获取 cell 对应的模型

Food *food = self.foods[indexPath.row];

//1.创建 vc

ComposeController *vc = [[ComposeController alloc]init];

UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];

//3.传值

vc.food = food;

//2.展示 vc

vc.view.backgroundColor = [UIColor greenColor];

//    [self.navigationController pushViewController:vc animated:YES];

nav.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentViewController:nav animated:YES completion:nil];

}

//重写 set方法

- (void)setFoodType:(FoodType *)foodType

{

_foodType = foodType;

//加载对应的 plist  字典转模型  放在数组里面

NSString *path = [NSString stringWithFormat:@"type_%@_foods.plist",foodType.idstr];

_foods = [Food objcWithFileName:path];

//设置标题

self.title = foodType.name;

//刷新列表

[self.tableView reloadData];

}

@end

#import "ComposeController.h"

#import "Food.h"

@interface ComposeController ()

@property (nonatomic ,weak)  UIWebView *webView ;

@end

@implementation ComposeController

- (void)loadView

{

UIWebView *webView = [[UIWebView alloc]init];

self.view = webView;

self.webView = webView;

}

- (void)viewDidLoad {

[super viewDidLoad];

//添加 item

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(back)];

//拼接路径

NSString *name = [NSString stringWithFormat:@"Html/food/%@.html",self.food.idstr];

NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];

//加载

NSURL *url = [NSURL fileURLWithPath:path];

NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];

[self.webView loadRequest:request];

}

//- (void)setFood:(CZFood *)food

//{

//    _food = food;

//

//    NSString *name = [NSString stringWithFormat:@"%@.html",self.food.idstr];

//

//    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];

//

//    //加载

//

//    NSURL *url = [NSURL fileURLWithPath:path];

//    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];

//    [self.webView loadRequest:request];

//

//

//}

- (void)back

{

[self dismissViewControllerAnimated:YES completion:nil];

}

@end

- (void)viewDidLoad {

[super viewDidLoad];

//获取自控制器

UINavigationController *nav1 = self.childViewControllers[0];

MasterController *masterVc = nav1.childViewControllers[0];

UINavigationController *nav2 = self.childViewControllers[1];

DetailController *detailVc = nav2.childViewControllers[0];

masterVc.delegate = detailVc;

self.delegate = detailVc;

}

@end

iPad学做菜的更多相关文章

  1. ALGO-120_蓝桥杯_算法训练_学做菜

    问题描述 涛涛立志要做新好青年,他最近在学做菜.由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种原料标上字母A,B,C,D. 涛涛现在会做的菜有五种: . 西红柿炒鸡蛋 ...

  2. C语言 · 学做菜

    算法训练 学做菜   时间限制:1.0s   内存限制:256.0MB      问题描述 涛涛立志要做新好青年,他最近在学做菜.由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我 ...

  3. 蓝桥杯 算法训练 ALGO-120 学做菜

    算法训练 学做菜   时间限制:1.0s   内存限制:256.0MB 问题描述 涛涛立志要做新好青年,他最近在学做菜.由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种 ...

  4. Java实现 蓝桥杯VIP 算法训练 学做菜

    算法训练 学做菜 时间限制:1.0s 内存限制:256.0MB 问题描述 涛涛立志要做新好青年,他最近在学做菜.由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种原料标上 ...

  5. 第25周五迷茫定位&转行理论建议

    今天下午请假办了无房证明和单身证明,准备开始贷款买房的征程,在犹豫纠结中我选择推进这个事情,之前的经验告诉我生活中可以面临改变或不改变境况的选择是要尽可能的选择改变,因为我还年轻.回来后知乎上看了一个 ...

  6. 微信小程序开发-窗体设置

    "window": { "backgroundTextStyle": "light", "navigationBarBackgro ...

  7. hihocoder #1015 KMP

    #include<stdio.h> #include<iostream> #include<math.h> #include<string.h> usi ...

  8. 【github】论怎么去写一个高大上的ReadMe

    前言 以前我时常觉得,自己写的ReadMe很单调乏味,但后来仔细研究一下后,发现有很多方式可以让ReadMe在简洁的基础上变得好看些,所以在这里和大家分享,如果大家有更好的想法,也非常欢迎在评论区留言 ...

  9. Python爬虫帮你打包下载所有抖音好听的背景音乐,还不快收藏一起听歌【华为云技术分享】

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/devcloud/article/detai ...

随机推荐

  1. WCF+AJAX最佳实践

    本文是基于Frank Xu的一个webcast上的串并总结,图片等都截至视频,谨致谢. 路线图 什么是WCF Windows Communication Foundation是MS为构建面向服务的应用 ...

  2. java 根据时间生成唯一id

    主要是依据当前系统毫秒数,但若用循环测试,同一毫秒依然会循环很多次, 系统毫秒数是13位, 公司的解决方法是再加5位的自增数,从00001开始, 于是登录淘宝查看,淘宝的id是13位的数字,猜测应该是 ...

  3. python学习第二天 --变量及其字符串

    python变量: 在计算机程序中,变量不仅可以是数字,还可以是任意数据类型. 在Python程序中,变量是用一个变量名表示,变量名必须是大小写英文.数字和下划线(_)的组合,且不能用数字开头. 在P ...

  4. Codeforces 366C Dima and Salad

    http://codeforces.com/problemset/problem/366/C 题意:在一个冰箱里有n种水果,并且这些水果每一种都有一个美味度和一个卡路里的属性, 小明要从这些水果中选出 ...

  5. 《Programming WPF》翻译 第3章 4.我们进行到哪里了?

    原文:<Programming WPF>翻译 第3章 4.我们进行到哪里了? 控件是由应用程序创建的块.它们描述了用户用来交互的界面特征.控件提供了行为,依赖样式和模板来表示一个外观.输入 ...

  6. android showAsDropDown的用法属性介绍

    使用PopupWindow可实现弹出窗口效果,,其实和AlertDialog一样,也是一种对话框,两者也经常混用,但是也各有特点.下面就看看使用方法.首先初始化一个PopupWindow,指定窗口大小 ...

  7. Berserk Rook

    Berserk Rook As you may know, chess is an ancient game for which almost everyone has at least a basi ...

  8. logstash 内置匹配IP

    10.252.142.174 - - [06/Sep/2016:08:41:36 +0800] "GET /api/validate/code/send?mobilePhone=186522 ...

  9. base64计算

    zjzc01:/root# cat aa.pl use URI::Escape; use URI::Escape qw(uri_unescape); use MIME::Base64; use Dig ...

  10. 【LeetCode练习题】Remove Duplicates from Sorted List II

    Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...