View Controller学习笔记—第一章Overview

初识Container View Controller 本文介绍了Container View Controller的简单使用,包括添加,移除,自定义专场动画等。 阅读详情

各位iOS开发大佬们好:
我是一名Swift+SwiftUI栈的iOS小白,目前还在上大三,最近准备实习,面试的过程中发现现在大公司很多还在用OC + UIKit的技术栈,OC我还在考虑要不要学,目前想先把UIKit学完,这是我在官网学习UIKit英文文档时摘录的本人认为的重点,如果你们也觉得对你们有用的话欢迎持续关注,我大概一天更一节,有事除外。格式什么的我也就不做了,翻译都是我自己翻译的,哪里不对欢迎在评论区指正,感谢各位大佬支持

今天2021年12月11日
这一章叫做Overview

The Role of View Controllers

View controller(以下尊称为VC)是app的基础,每个app都至少有一个VC,VC管理着UI的本身,UI与数据,UI与UI之间的变化

The UIViewController class defines the methods and properties for managing your views, handling events, transitioning from one view controller to another, and coordinating with other parts of your app. You subclass UIViewController (or one of its subclasses) and add the custom code you need to implement your app’s behavior.
UIViewController类定义了管理视图,处理事件,转换,与其他视图协调的方法和属性,通过继承UIViewController类或其子类来自定义实现app需要的行为

There are two types of view controllers:
Content view controllers manage a discrete piece of your app’s content and are the main type of view controller that you create.
Container view controllers collect information from other view controllers (known as child view controllers) and present it in a way that facilitates navigation or presents the content of those view controllers differently.
Most apps are a mixture of both types of view controllers.
两类VC:
内容VC管理app中的独立内容
容器VC从其他VC(一般是子VC)收集信息,并以方便导航或以不同方式显示这些视图控制器内容的方式呈现信息。

VC最重要的职责就是管理视图层级
在这里插入图片描述

It is common practice to use outlets to access other views in your view controller’s view hierarchy. Because a view controller manages the content of all its views, an outlet is a property of an object that references another object. outlets let you store references to the views that you need.
通过outlets可以在视图层级中访问其他视图,outlets就是一个储存了其他对象引用的对象属性

A content view controller manages all of its views by itself. A container view controller manages its own views plus the root views from one or more of its child view controllers. The container does not manage the content of its children. It manages only the root view, sizing and placing it according to the container’s design.
内容VC管理了它视图层级下的所有视图,包括其子VC下的所有视图,容器VC就不鸟它的子VC了,根据设计设置尺寸和位置
在这里插入图片描述

A view controller acts as an intermediary between the views it manages and the data of your app. The methods and properties of the UIViewController class let you manage the visual presentation of your app. When you subclass UIViewController, you add any variables you need to manage your data in your subclass. Adding custom variables creates a relationship like the one in Figure 1-3, where the view controller has references to your data and to the views used to present that data. Moving data back and forth between the two is your responsibility
VC是UI和数据之间的桥梁,在VC中处理数据和显示方式,
You should always maintain a clean separation of responsibilities within your view controllers and data objects. Most of the logic for ensuring the integrity of your data structures belongs in the data objects themselves. The view controller might validate input coming from views and then package that input in the format that your data objects require, but you should minimize the view controller’s role in managing the actual data.
你需要划清VC和数据对象之间的责任界限,确保数据结构完整性的大多数逻辑都属于数据对象本身,尽量不要让VC处理实际数据

A UIDocument object is one way to manage your data separately from your view controllers. A document object is a controller object that knows how to read and write data to persistent storage. When you subclass, you add whatever logic and methods you need to extract that data and pass it to a view controller or other parts of your app. The view controller might store a copy of any data it receives to make it easier to update views, but the document still owns the true data.
UIDocument对象是独立于VC管理数据的好东西,它知道如何从持久化存储中读取数据,继承时可以添加一些你需要的方法取出数据并将其传给VC或app的其他部分使用,VC会拿到值后保存一份copy,document仍旧持有原值

View controllers are responder objects and are capable of handling events that come down the responder chain. Although they are able to do so, view controllers rarely handle touch events directly. Instead, views usually handle their own touch events and report the results to a method of an associated delegate or target object, which is usually the view controller. So most events in a view controller are handled using delegate methods or action methods.
VC不直接处理触摸事件,一般是view响应之后将结果传给他们关联的代理或目标对象,而这些关联的代理或目标对象基本上就是VC

The UIViewController class handles most aspects of view management automatically. For example, UIKit automatically releases any view-related resources that are no longer needed. In your UIViewController subclasses, you are responsible for managing any objects you create explicitly.
When the available free memory is running low, UIKit asks apps to free up any resources that they no longer need. One way it does this is by calling the didReceiveMemoryWarning method of your view controllers. Use that method to remove references to objects that you no longer need or can recreate easily later.
UIViewController类管的很宽,比如UIKit会自动释放掉和所有不再需要的视图有关的资源,如果你继承了子类,那么你也需要显式的管的和它一样宽。
如果内存不太够了,UIKit会通过调用VC的 didReceiveMemoryWarning 方法释放掉所有不再需要的或那些可以很轻松重新创建的资源

Adaptivity
View controllers are responsible for the presentation of their views and for adapting that presentation to match the underlying environment. Every iOS app should be able to run on iPad and on several different sizes of iPhone. Rather than provide different view controllers and view hierarchies for each device, it is simpler to use a single view controller that adapts its views to the changing space requirements.
In iOS, view controllers need to handle coarse-grained changes and fine-grained changes. Coarse-grained changes happen when a view controller’s traits change. Traits are attributes that describe the overall environment, such as the display scale. Two of the most important traits are the view controller’s horizontal and vertical size classes, which indicate how much space the view controller has in the given dimension. You can use size class changes to change the way you lay out your views, as shown in Figure 1-4. When the horizontal size class is regular, the view controller takes advantage of the extra horizontal space to arrange its content. When the horizontal size class is compact, the view controller arranges its content vertically.

在这里插入图片描述

Within a given size class, it is possible for more fine-grained size changes to occur at any time. When the user rotates an iPhone from portrait to landscape, the size class might not change but the screen dimensions usually change. When you use Auto Layout, UIKit automatically adjusts the size and position of views to match the new dimensions. View controllers can make additional adjustments as needed.
适配性
VC需要管理app在不同尺寸型号设备上的显示情况,还包括横竖屏,可显示的区域等等

The View Controller Hierarchy

Maintaining the proper view controller relationships ensures that automatic behaviors are delivered to the correct view controllers when they are needed. If you break the prescribed containment and presentation relationships, portions of your app will stop behaving as expected.
VC之间的关系定义了每个VC需要的行为,如果你破坏了预先设置好的关系,那么将造成一些不好的影响
根视图的VC是这个VC层级的中心,每个Window都有且仅有一个填满整个window的根视图VC,根视图VC定义了用户所见的初始内容
在这里插入图片描述

通过UIWindow对象的rootViewController 属性设置根视图VC,SB中会自动设置,但我不是SB哈哈哈,开玩笑,我不用StoryBorad,代码方式必须手动设置
容器VC,例如UINavigationController对象会将它的子VC中的内容和它的navigation bar和可选的toolbar一起显示,还有一些比如 UINavigationController, UISplitViewController, 和 UIPageViewController.
容器类一般就是window的根VC,他们也可以被当作子VC,都行,他们负责布局子VC,子VC一般不需要它的上峰是谁(这两天吃饭时间看新世界,看了两集觉得是个神剧,真狗血,上峰的上峰是上峰的爸爸)

在这里插入图片描述

When container view controllers are involved, UIKit may modify the presentation chain to simplify the code you have to write. Different presentation styles have different rules for how they appear onscreen—for example, a full-screen presentation always covers the entire screen. When you present a view controller, UIKit looks for a view controller that provides a suitable context for the presentation. In many cases, UIKit chooses the nearest container view controller but it might also choose the window’s root view controller. In some cases, you can also tell UIKit which view controller defines the presentation context and should handle the presentation.
替换视图时,UIKit会将旧VC和新VC连起来,替换的时候会匹配新旧,比如全屏替换,则新VC必须也得是可以覆盖全屏或者一个window的根VC,UIKit会提供一个合适的上下文,你可以配置哪个VC提供上下文并且管理替换

在这里插入图片描述
在这里插入图片描述

Design Tips

Use System-Supplied View Controllers Whenever Possible
官方肯定还是希望用自己家的东西,为了阻止你自定义乱七八糟的东西,Apple说了,在你自定义之前,学习一下底下这些东西
The UIKit framework provides view controllers for displaying alerts, taking pictures and video, and managing files on iCloud. UIKit also defines many standard container view controllers that you can use to organize your content.
The GameKit framework provides view controllers for matching players and for managing leaderboards, achievements, and other game features.
The Address Book UI framework provides view controllers for displaying and picking contact information.
The MediaPlayer framework provides view controllers for playing and managing video, and for choosing media assets from the user’s library.
The EventKit UI framework provides view controllers for displaying and editing the user’s calendar data.
The GLKit framework provides a view controller for managing an OpenGL rendering surface.
The Multipeer Connectivity framework provides view controllers for detecting other users and inviting them to connect.
The Message UI framework provides view controllers for composing emails and SMS messages.
The PassKit framework provides view controllers for displaying passes and adding them to Passbook.
The Social framework provides view controllers for composing messages for Twitter, Facebook, and other social media sites.
The AVFoundation framework provides a view controller for displaying media assets.

学完你肯定能(已)找(经)到(吐)能(血)用(了)的

Never modify the view hierarchy of system-provided view controllers. Each view controller owns its view hierarchy and is responsible for maintaining the integrity of that hierarchy. Making changes might introduce bugs into your code or prevent the owning view controller from operating correctly. In the case of system view controllers, always rely on the publicly available methods and properties of the view controller to make all modifications
不仅如此你还不能动人家VC系统的视图层级,它依赖于公开的方法和属性做所有的修改

In cases where two view controllers need to communicate or pass data back and forth, they should always do so using explicitly defined public interfaces.
尽可能让每个VC独立,少知道其他人的情况,做好自己的事,如果两个VC需要联系,他们应该用显式定义好的公共接口
The delegation design pattern is frequently used to manage communication between view controllers. With delegation, one object defines a protocol for communicating with an associated delegate object, which is any object that conforms to the protocol. The exact type of the delegate object is unimportant. All that matters is that it implements the methods of the protocol.
代理模式在两个VC之间联系时非常常用,一个对象定义了一个与它关联的代理对象的协议,另一个对象遵守协议,代理对象的类型不重要,重要的是它得实现协议的方法

Use the Root View Only as a Container for Other Views
Use the root view of your view controller solely as a container for the rest of your content. Using the root view as a container gives all of your views a common parent view, which makes many layout operations simpler. Many Auto Layout constraints require a common parent view to lay out the views properly.
可以用根视图仅作为作为其他内容的一个容器,许多自动布局约束需要公共父视图才能正确布局视图。

Know Where Your Data Lives
In the model-view-controller design pattern, a view controller’s role is to facilitate the movement of data between your model objects and your view objects. A view controller might store some data in temporary variables and perform some validation, but its main responsibility is to ensure that its views contain accurate information. Your data objects are responsible for managing the actual data and for ensuring the overall integrity of that data.
MVC模式下VC的一个职责就是明确数据在V和M之间的移动,VC可能会存储一些临时变量,M的职责为管理实际数据,确保这些数据的实体完整性。
Adapt to Changes
适应不同环境,包括设备尺寸,横竖屏,分屏

Ruby on Rails,通过实例变量从Controller向View传递数据 http://blog.youkuaiyun.com/abbuggy/article/details/7627460 Controller是MVC框架的核心,从名字就可以看出Controller存在的意义就是要“控制”,这里的“控制”有两个含义。 第一是要控制页面的流转也就是决定调用哪个合适的View来展示数据,在《Ruby on Rails,在Controller中指定渲染的Templates》和《 阅读详情

相关推荐

MVC架构中使用ajax实现view和controller之间值的传递

最近在写网站,被一个很简单的问题困扰了两天~由于

点点滴滴 3123

由viewWillAppear没有被调用见控制器结构设计上的误区

<br /><br />问题<br /> <br />Hi,<br />I'm stuck! I can't see why viewWillAppear doesn't run in my code but viewDidLoad runs. If I understand it correctly viewDidLoad runs once on the first instance and viewWillAppear runs every time a view is added to the st

SlimApp 1155

Keil C51开发必看:详解data/xdata/bdata内存分配陷阱与避坑指南

本文深入解析Keil C51开发中的data/xdata/bdata内存分配陷阱,提供针对51芯片的高效避坑指南。通过真实案例揭示Keil编译器的隐藏规则,分享内存优化策略和调试技巧,帮助开发者解决data溢出、xdata访问异常等典型问题,提升嵌入式开发效率。

v6b7n8m9q0的博客 1072

【IOS笔记】View Programming Guide for iOS -1

原文:View Programming Guide for iOS View and Window Architecture Views and windows present your application’s user interface and handle the interactions with that interface. UIKit and other syste...

weixin_30852451的博客 226

UE5在Ubuntu22.04.4下的高效开发环境配置指南

本文详细介绍了在Ubuntu 22.04.4系统上配置UE5高效开发环境的完整指南,包括系统准备、显卡驱动安装、UE5引擎编译与配置、开发工具链设置以及性能优化技巧。通过逐步指导,帮助开发者快速搭建稳定的UE5开发环境,解决常见问题,提升开发效率。

weixin_29251131的博客 383

stm32cubeMX使用HAL库点亮LED流水灯

目录

weixin_46129506的博客 3799

ArcEngine错误提示

错误代码 错误名称 错误描述 HRESULT:0x80040201 FDO_E_LOADING_RESOURCE “Failed to load a resource (string, icon, bitmap, etc).” HRESULT:0x80040202 FDO_E_INDEX_OUT_OF_RANGE The index passed was not wit

默而识之者 1万+

使用SpringBoot+Vue3开发项目(1)---- 设计用户注册和登录的接口及页面

本文基于黑马大事件项目介绍如何使用SpringBoot+Vue3来实现前后端联调的登录与注册操作。

记得开心一点嘛的博客 3644

View Controller Programming Guide for iOS---(五)---Resource Management in View Controllers

Resource Management in View Controllers View controllers are an essential part of managing your app’s resources. View controllers allow you to break your app up into multiple parts and instantia...

240

心理学量表汇总 50多个 附下载

目录一、心理健康与精神病态量表二、行为问题量表三、人格评估量表四、智力测验一、心理健康与精神病态量表1.一般症状自评量表(SCL-90)症状自评量表 (The self-report symptom inventory ,Symptom checklist ,90,简称 SCL90) 有 90 个评定项目 , 每个项目分五级评分 , 包含了比较广泛的精神病症状学内容, 从感觉、 情 感、思维、意识、行为直至生活习惯、人际关系、饮食等均有涉及,能准确刻划被试的自觉 症状,能较好地反映被试的问题及其严重程度和变

南七小僧的学海无涯 1906

PSINS工具箱学习(四)捷联惯导更新算法

原始 Markdown文档、Visio流程图、XMind思维导图见:https://github.com/LiZhengXiao99/Navigation-Learning。

实践出真理,接毕设/课设项目开发指导 607

View Controller Programming Guide for iOS---(三)---Using View Controllers in Your App

Using View Controllers in Your App Whether you are working with view controllers provided by iOS, or with custom controllers you’ve created to show your app’s content, you use a similar set of t...

282

YOLO26-seg分割优化:轻量化卷积魔改 | 新的partial convolution(PConv)结合C3k2 | CVPR2023

​​​​​摘要:本研究对Ultralytics YOLO26进行了全面分析,重点阐述了其关键架构改进及其在实时边缘目标检测中的性能基准测试。YOLO26于2025年9月发布,是YOLO系列最新、最先进的成员,专为在边缘及低功耗设备上实现高效、精确且易于部署的目标而构建。本文依次详述了YOLO26的架构创新,包括:移除了分布焦点损失(DFL);采用端到端的无NMS推理;集成了渐进损失(ProgLoss)与小目标感知标签分配(STAL);以及引入了用于稳定收敛的MuSGD优化器。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 153

Spring MVC 学习笔记4 ——Controller 与 View 互相传值

Spring MVC 传值(一) 1. 从视图传值给Controller Internal View Resolver 方法, 通过函数的参数来传递。 在HelloController.java文件中, ----------- @RequestMapping({"/hello"}) public String hello(String stringIn){ //此时在浏览器中

Combine Art and Sciences. 3294

Midscene.js(3):手把手教你用 YAML 脚本实现 AI 驱动的 Web UI 自动化「喂饭教程」

Midscene.js是一款开源的AI驱动UI自动化工具,通过自然语言描述即可控制浏览器或Android设备执行操作。它支持YAML脚本编写测试用例,降低了自动化测试门槛。

blues_C的博客 3247

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Qt 项目中的View、Controller

2019-11-05 我发现,一些Qt项目中,开发者因为Qt的框架提供了很好的解耦方式,便不再关注controller,把widget class 当作controller。这实在是不应该。在这样的代码基础上进行下去,就会发现所有的东西都逐渐放在了widget上。超大的cpp文件,ui、逻辑、数据库操作,混杂,不可直视。在这里,我们假设系统比较简单,MVC中Model包含了数据库访问(DAO...

know yourself 1032

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

关于view、controller、service、dao的理解

最近,越来越对这几层的含义有兴趣,因此,根据在网上搜索到的资料以及自己的理解,特整理了这篇博文。        首先,分层的目的:高内聚,低耦合。虽然有时候一个controller方法里面仅仅调用一个service的方法,一个service方法里面仅仅调用一个dao层里的方法,但是,这几层还是非常有必要存在的。一、这样看起来结构是很清晰的,虽然对很对新人来说确实看起来很复杂;二、可扩展性和适应性更...

u013594528的博客 8545

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【Asp.Net MVC】Controller和View之间传递数据

在MVC中,Controller和View之间是如何传递数据的呢? 一、Controller向View传递数据 1、ViewBag Controller  public ViewResult TransData()         {              ViewBag.TGB = "大米时代";             return View();

柠檬树 8222

【MVC框架】——View和Controller之间的传值

    在MVC中,Controller执行一个可以说是路由功能,它通过View传过来的数据,来决定应该调用哪一个Model,同样会把Model处理完的数据传给View,所以就总是涉及到Controller和View的传值,那么它们之间是怎么传值的呢?   Controller向View传值   1、使用ViewBag   Controller   &lt;span style=...

Coder Yasmine 9865

php controller view,在php中Controller向View传值

想用MVC的方式写一个小的CMS,建立了Controller、Model、View,但是不知道Controller向view传值应该怎么写?index.phpshow();?>testController.class.phpclass testController{function show(){$testModel = new testModel();$data = $testModel-...

weixin_42300721的博客 327

将Controller中的数据传递到View中显示

如何将Controller 中的数据传送到View 步骤: (1)要有数据,如果要用到对象可以在Model 中定义对应的类 (2)要有装数据的容器: System.Text.StringBuilder sbHtml = new System.Text.StringBuilder(4000); (3)要将数据放入容器: sbHtml.AppendLine(""+d.ToString()+""

lzz360的专栏 8698

Controller与View相互间传递数据

<br />在ASP.NET MVC中,经常会在Controller与View之间传递数据,因此,熟练、灵活的掌握这两层之间的数据传递方法就非常重要。本文从两个方面进行探讨: <br /><br />Controller向View传递数据<br /><br />View向Controller传递数据<br /><br /><br />一、Controller向View传递数据<br /><br /><br /><br />1.<br />使用ViewData传递数据<br /><br /><br />我们在

学习无止境 2834

Backbone入门(View,Controller)

ViewBackbone 的 Views 用来接收用户的操作和修改 Model 的数据 ,另外通过 render 来展示数据.实际上,在MVC框架中,它更像是Controller。View有两个作用:1.监听事件2.展示数据下面简单的创建一个View:GameView= Backbone.View.extend({    tagName : "div",    className: "game",

幻影浪子 9195

springMV中的view-controller的作用

最近阅读spring官方文档的时候,接触到了一些关于MVC命名空间下的一些属性,查看学习官方文档后记录下下来方便以后的学习;首先我来看一下view-controller这个属性是用来干什么的。     先来看一段代码,下面这段代码的作用是在Controller中实现一个页面的跳转功能。 @Controller @RequestMapping("index") public class Test

zhengyangzkr的博客 2826

3.Controller与View

 <!--v/:* {behavior:url(#default#VML);}o/:* {behavior:url(#default#VML);}w/:* {behavior:url(#default#VML);}.shape {behavior:url(#default#VML);}-->这节我们让ASP.NET MVC真正的跑起来一、新建Controller

祈离的专栏 666

如何拆分View Controller进而实现轻量级的View Controller[UIKit]

参考文章来自objcio网站   为什么要编写轻量级的View Controller??   1、作为iOS项目中最大的文件,View Controllers中的代码复用率几乎是最低的 2、重量级的View COntroller加大了测试的复杂度。   所以关注View Controller的瘦身,把业务逻辑、网络请求、Views的代码移到合适的地方,进而提高代码可读性、降低耦合

天天爱增肥 2231
上一篇: Core Animation学习笔记—第十节Key-Value Coding Extensions
下一篇: View Controller学习笔记—第二章View Controller Definition
诚是张嘉诚
博客等级 码龄7年 15粉丝 24原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值