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

主要技术:主界面采用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. oracle 存储过程返回结果集 (转载)

    好久没上来了, 难道今天工作时间稍有空闲, 研究了一下oracle存储过程返回结果集. 配合oracle临时表, 使用存储过程来返回结果集的数据读取方式可以解决海量数据表与其他表的连接问题. 在存储过 ...

  2. ios文件读取(二)

    - (void)viewDidLoad { [super viewDidLoad]; /** *  @brief 获取文件路径 * */ NSString * filePath = [self get ...

  3. DTO学习系列之AutoMapper(六)----EntityFramework和AutoMapper的婚后生活

    写在前面 我到底是什么? 越界的可怕 做好自己 后记 文章标题主要关键字:mapping DTOs to Entities,注意并不是“Entities to DTOs”,表示实体对象到DTO的转换, ...

  4. android如何保存读取读取文件文件保存到SDcard

    android如何保存读取读取文件文件保存到SDcard 本文来源于www.ifyao.com禁止转载!www.ifyao.com 上图为保存文件的方法体. 上图为如何调用方法体保存数据. 上面的截图 ...

  5. 客户端技术:Cookie 服务端技术:HttpSession

    客户端技术:Cookie 服务端技术:HttpSession 07. 五 / android基础 / 没有评论   一.会话技术1.什么是会话:客户打开浏览器访问一个网站,访问完毕之后,关闭浏览器.这 ...

  6. 从配置文件中读取数据获取Connection

    配置文件 db.driver=com.mysql.jdbc.Driver db.url=jdbc\:mysql\://localhost\:3306/mybase db.user=root db.ps ...

  7. 关于jquery-easyUI中主键属性data-options的了解

    data-options是jQuery Easyui 最近两个版本才加上的一个特殊属性.通过这个属性,我们可以对easyui组件的实例化可以完全写入到html中,例如: <div class=& ...

  8. [转]JS基础之undefined与null的区别

    在JavaScript开发中,被人问到:null与undefined到底有啥区别? 一时间不好回答,特别是undefined,因为这涉及到undefined的实现原理.于是,细想之后,写下本文,请各位 ...

  9. 怎样利用putty登陆SSH主机方法

    PuTTY 是一套免费的SSH / Telnet 程序,是在Windows 32平台下的telnet.rlogin和ssh客户端,它是一个跨平台的远程登录工具 下载putty成功后,双击打开Putty ...

  10. linux服务器wget无法成功解析域名及程序获取外网数据不稳定问题

    1.问题描述: 1.1 最近发现通过linux服务器wget下载远程文件经常提示无法解析域名问题,要重复多次才能成功,成功率比较低. 1.2 PHP用file_get_contents()函数获取淘宝 ...