iPad学做菜
项目描述:家常菜、川菜 、鲁菜、东北菜、甜品等各大菜系应有尽有,详细的制作步骤,再也不用为自己不会做饭而烦恼。
主要技术:主界面采用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学做菜的更多相关文章
- ALGO-120_蓝桥杯_算法训练_学做菜
问题描述 涛涛立志要做新好青年,他最近在学做菜.由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种原料标上字母A,B,C,D. 涛涛现在会做的菜有五种: . 西红柿炒鸡蛋 ...
- C语言 · 学做菜
算法训练 学做菜 时间限制:1.0s 内存限制:256.0MB 问题描述 涛涛立志要做新好青年,他最近在学做菜.由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我 ...
- 蓝桥杯 算法训练 ALGO-120 学做菜
算法训练 学做菜 时间限制:1.0s 内存限制:256.0MB 问题描述 涛涛立志要做新好青年,他最近在学做菜.由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种 ...
- Java实现 蓝桥杯VIP 算法训练 学做菜
算法训练 学做菜 时间限制:1.0s 内存限制:256.0MB 问题描述 涛涛立志要做新好青年,他最近在学做菜.由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种原料标上 ...
- 第25周五迷茫定位&转行理论建议
今天下午请假办了无房证明和单身证明,准备开始贷款买房的征程,在犹豫纠结中我选择推进这个事情,之前的经验告诉我生活中可以面临改变或不改变境况的选择是要尽可能的选择改变,因为我还年轻.回来后知乎上看了一个 ...
- 微信小程序开发-窗体设置
"window": { "backgroundTextStyle": "light", "navigationBarBackgro ...
- hihocoder #1015 KMP
#include<stdio.h> #include<iostream> #include<math.h> #include<string.h> usi ...
- 【github】论怎么去写一个高大上的ReadMe
前言 以前我时常觉得,自己写的ReadMe很单调乏味,但后来仔细研究一下后,发现有很多方式可以让ReadMe在简洁的基础上变得好看些,所以在这里和大家分享,如果大家有更好的想法,也非常欢迎在评论区留言 ...
- Python爬虫帮你打包下载所有抖音好听的背景音乐,还不快收藏一起听歌【华为云技术分享】
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/devcloud/article/detai ...
随机推荐
- LAMP架构搭建+Discuz论坛搭建【weber出品必属精品】
一. 本机简介: 本机系统: CentOS-6.4-x86_64 主机名:oracle.ywb IP地址:192.168.146.129 二. 在Linux环境下安装Apache步骤 ...
- JS控制文本框textarea输入字数限制的方法
<html> <head runat="server"> <title></title> <script type=" ...
- gitosis随记
0.创建git用户 useradd -m git passwd git 1.安装脚本工具(gitosis依赖python) apt-get install python-setuptools 2.gi ...
- 编译XSIP过程中环境配置
昨天在编译XSip的过程中,有很多问题首先是出现了很多的error C1083. 然后到XSIP自己的文件夹中,也找不到对应的.h文件. 上网查阅后发现应该是缺少了对应的头文件的路径. 于是到可以 ...
- C++ 使用cl命令编辑时发生的问题收录
1.cl不是内部或这外部命令,也不是可运行的程序或批处理文件. 这个问题的出现的原因是因为系统找不到cl命令处理程序,无法识别,解决办法: 首先在C盘查找cl.exe,可能会查到多个,先选择第一个,将 ...
- 帝国cms实现自动生成缩略图和自动分页功能
无论你手工发布,还是采集而来,免不了要进行手工操作弄缩略图,不然标题图片没有,挺烦人的 只需一次设定,就可以在文章编辑框里自动勾选上分页和生成缩略图,免除你次次进行操作的麻烦,好了,废话不多说,上菜“ ...
- Spring Data JPA之Hello World
Spring Data Jpa 配置 使用 Spring Data JPA 进行持久层开发需要的四个步骤: 1.配置 Spring 整合 JPA 2.在 Spring 配置文件中配置 Spring D ...
- python安装setuptools和pip
今天需要写一个python导出excel的小程序.这里需要用到XlsxWriter模块,但是这个模块并没有安装,所以需要先下载该模块,然后才能在程序中使用.这里就需要安装模块,我选择使用pip.以下就 ...
- ios 多线程 面试
1 多线程是什么 同步完成多项任务,提高了资源的使用效率,从硬件.操作系统.应用软件不同的角度去看,多线程被赋予不同的内涵,对于硬件,现在市面上多数的CPU都是多核的,多核的CPU运算多线程更为出色 ...
- Linux配置完iptables后,重启失效的解决方案
Linux配置完iptables后,重启失效的解决方案 因为只有root用户才可访问1024以下的端口,非root用户登陆是不能启用80端口的.web service 往往启动1024以上的端口,并通 ...