苹果官方文档View Controller Programming Guide for iOS
关于iOS组件化网上资料太多,这里只是从个人观点说明一下怎么使用组件化和使用组件化的优点和缺点 首先下载CTMediatorDemo
1、iOS上的页面展示和逻辑 1.1 iOS的MVC设计模式 在介绍iOS的页面展示之前,我们需要先知道iOS应用的运行逻辑和设计模式。MVC即Model,View,Controller(模型,视图,控制器)。 View上展示的东西,由Model来定义 View上展示的逻辑,由Controller来控制 Controller同样负责初始化Model,和传递Model的信息给View 用户在View层中所进行的创建或修改数据的操作,通过Controller对象传达出去,最
自从block出现之后,很多API都开始采用这样的结构,由此可见,block确实有许多优势存在,这里将一些简单用法总结如下:
IOS SDK6/Xcode4.5开始在Storyboad中新增很多功能对可视化的开发页面布局,导航更加方便,下面就写一下各种导航的实现。 1、不用像Xcode4之前必须删除默认的viewcontro
在iOS开发过程中,我们经常性会需要获取当前页面的ViewController,然后利用ViewController进行一些操作,例如在最顶层的ViewController上展示一个UIAlertController,或者在最顶层的ViewController上present另一个ViewController,或者进行其他操作。 1 实现思路 通过最底层的ViewController依次向上寻找,直到找到最顶层的ViewController,也就是从UIApplication的keyWindow的r
前言 由于公司要开发一款小说类阅读APP,其中体验上非常重要的一点便是翻页效果。为了实现翻页效果,我查询了很多资料后选择使用了UIPageViewController。原因很简单,使用方便,功能强大,
在macOS 10.10之后,关于NSViewController,苹果公司专门在一个extension中提供了四个方法用来处理控制器之间的关系以及切换转场处理.
看似常用的UIView,其实有很多不经常用到的方法和应该注意的机制,我是一个喜欢打破砂锅问到底的人,可是很多问题在网上搜索不到答案,大部分的博客都是转载相同的东西,所以我自己就新建 Dome,实际测试了一些数据,得到了一些有用的东西,分享给大家,其中也用到了其它大神的理论和指点,在此感谢。
在一款完整iOS移动应用的开发中,代码的调试和编写占着同等重要的地位。Xcode默认使用LLDB作为代码调试器,LLDB功能丰富且强大,恰当的使用它,可以帮助开发者事半功倍的完成代码调试的工作。
Apple在Xcode 8中对Interface Builder进行了很大的改进。使用大小类变得更加直观,缩放故事板的能力非常方便,Interface Builder中的完整预览功能非常棒。对于那些对使用Interface Builder犹豫不决的人来说,这可能会成为一个交易破坏者。
在使用 NSTimer,如果使用不得当特别会引起循环引用,造成内存泄露。所以怎么避免循环引用问题,下面我提出几种解决 NSTimer 的几种循环引用。
Clang的全称是C Language Family Frontend for LLVM,即基于LLVM的C系列语言的前端编译器。iOS应用的前端编译,即是采用Clang完成的。本篇文章,我们主要介绍Clang内置的一个简单的代码覆盖率检测功能,对于iOS开发来说,此功能更多用于Objective-C的方法插桩,为二进制重排提供支持,优化应用启动速度。但代码覆盖率检测功能并不仅仅只能应用与二进制重排,其本质是对于函数级、基本块级或代码边缘级插入回调,我们可以基于这一原理更灵活的实现所需要的功能。
运行程序发现student的delloc不会执行,因为在dosomethingBlock引用了ViewController,而Student又是ViewController属性,存在循环引用。 修改这个bug,只需要清掉其中一个引用即可
如果你的 app 有大量的窗口,故事板能帮你减少许多用于从一个窗口转到另一个窗口的导航代码。与每个viewcontroller一个单独的 nib 文件不同,你的 app 只需用一个故事板文件(其中可以包含所有的viewcontroller 以及它们之间的关系)即可。
不同于国外,StoryBoard从面世到如今饱受国内开发者的质疑,质疑的理由很多,什么不利于多人协作啊,隐藏了UI细节啊,出问题不容易测试,降低执行效率啊等等。此文就是针对这些问题的举例和剖析。
记得当前通过serverlet来写jsp页面的时候有些代码还是通过后面直接写到页面来的,好恶心,什么东西都是通过后面来写的,包括静态代码,并且维护极其费时费力,真是辛酸岁月,好在后面mvc很好解决了该问题。
或者修改 rootViewController参数 2、弹出框: import UIKit class ViewController:UIViewController { var label:UILabel! override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.brown label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = ”” self.view.addSubview(label) let button = UIButton(frame:CGRect(x:40, y:180,width:240, height:44)) button.setTitle(“打开新的视图控制器”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget(self, action:#selector(ViewController.openViewController),fo:.touchUpInside) self.view.addSubview(button) } func openViewController() { let newViewController = NewViewController() newViewController.labelTxt = “传递的参数!” newViewController.viewController = self self.present(newViewController, animated:true,completion:nil) } }
这篇文档上说的比较详细:https://www.jianshu.com/p/dd6775219869
响应链是一种消息处理机制,它是由一组有序的响应者对象组成的链条.当消息进入响应链条后,由响应者对象依次判断是否能够处理该消息,当一个响应者对象不能处理此条消息时,它会将消息传递给它的继任者(也就是它的下一个响应者对象). 响应链具有如下特性:
到目前为止我们还没有解释我们的程序是如何显示默认视图界面的。做过WinForm程序的朋友都知道每个Window窗口界面都有一个设计器(对应一个设计文件),其实在IOS中也可以通过设计工具设计界面不用编写代码,这个工具就是Interface Builder。用Interface Builder编辑的文件在iOS5之前是一个“.xib”文件,从IOS5开始进行了改进,使用“.storyboard”文件进行设计。其实在上面我们已经看到这个文件,这里重点说明一下Storyboard文件的使用。
项目的代码很多,前两天老大突然跟我说项目中某一个ViewController的dealloc()方法没有被调用,存在内存泄漏问题,需要排查原因,解决内存泄漏问题。由于刚加入项目组不久,对出问题的模块的代码还不太熟悉,所以刚拿到问题时觉得很棘手,再加上作为一个iOS菜鸟,对内存泄漏的排查方法和原因确实基本上不了解。所以,也借着这样的机会,我研究了一下关于iOS开发中内存泄漏的排查方法和原因分析。 首先,补充两个基本概念的解释: 内存溢出 (out of memory):是指程序在申请内存时,没有足够的内
有时候,我们可能需要统一工程中的返回按钮样式,比如都是 箭头+返回 或者都是 箭头。 方案有两种:
1.新建single view工程,导入MediaPlayer库,导入一个视频文件test1.mp4
2、弹出框: import UIKit class ViewController:UIViewController { var label:UILabel! override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.brown label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = ”” self.view.addSubview(label) let button = UIButton(frame:CGRect(x:40, y:180,width:240, height:44)) button.setTitle(“打开新的视图控制器”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget(self, action:#selector(ViewController.openViewController),fo:.touchUpInside) self.view.addSubview(button) } func openViewController() { let newViewController = NewViewController() newViewController.labelTxt = “传递的参数!” newViewController.viewController = self self.present(newViewController, animated:true,completion:nil) } }
在WTPerson.m中我们让accessInstanceVariablesDirectly返回NO,则程序直接崩溃。
作为MVC设计模式中的C,Controller一直扮演着项目开发中最重要的角色,它是视图和数据的桥梁,通过它的管理,将数据有条有理的展示在我们的View层上。iOS中的UIViewController是UIKit框架中最基本的一个类。从第一个UI视图到复杂完整项目,都离不开UIViewController作为基础。基于UIViewController的封装和扩展,也能够出色的完成各种复杂界面逻辑。这篇博客,旨在讨论UIViewController的生命周期和属性方法,在最基础的东西上,往往会得到意想不到的惊喜。
Xcode 升级到 5 之后, iOS 的 xib 文件发生了变化, 导致 Xamarin Studio 中自带的 iOS ViewController 模板出错了, 本文分析发生的错误, 并给出对应的解决方法。
可能是因为上面的缺点吧, Mvx 没有提供内置的 Storyboard 支持。 不过 Mvx 的扩展性是很强大的, 通过自定义 MvxTouchViewsContainer 就可以实现对 Storyboard 的支持。
实例化的时候使用TestView:TestView *view2 = [[TestView alloc] init];
MVC不是一个新概念,只要有一定开发经验的人基本都知道这个东东。但是之前在业界一直不温不火,直到IOS火起来,这个概念开始为人所熟识并加以运用。究其原因,个人以为是之前的人把MVC搞复杂了(例如ASP.net MVC),IT就是这样,技术越复杂就会越难被人理解接受,越不被人理解接受,自然就不会被大家推广使用。
1 创建:FirstViewController、SecondViewController 2、在FirstViewController的viewDidLoad设置属性 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. self.title = “第一页” self.view.backgroundColor = UIColor.brown self.navigationItem.rightBarButtonItem = UIBarButtonItem(title:”下一页”, style: UIBarButtonItemStyle.plain, target:self, action:
在使用view的缩放的时候,layer.border.width随着view的放大,会出现锯齿化的问题,解决这个问题需要设置这个属性。
APP中经常有根据标签来切换页面的需求,如果切换的页面只是刷新一下数据也就罢了,但是如果每个标签切换页面的数据和内容、结构完全不同你会怎么样做?(例如:图1-1) 图1-1 个人觉得理想的做法就是每个
iOS开发中,创建View常见的两种方式一个是纯代码,一个是借助于XIB;创建ViewController常见的也有两种方式一个是纯代码,一个是借助于StoryBoard。 通过交流我发现很多童鞋对这些概念都很模糊,于是通过实验写一篇博客供参考。 重写View的如下方法 @implementation YFView -(instancetype)init{ self = [super init]; NSLog(@"%s", __func__); re
结果如图,这里要注意一个问题,就是指向第一个显示ViewController的箭头 指向了SWRevealViewController; 因为我在实际开发中发现不指向这个ViewController 侧滑菜单不出现,不知道是什么原因
以前对MVVM的理解和运用觉得很浅薄,在项目中用处只是对ViewController减负
class ViewControllerHelper: NSObject { /// 通过ClassName动态创建ViewController /// - Parameter className: calssName /// - Returns: ViewController class func getViewControllerWithCalssName(_ className: String) -> UIViewController {
有很多人,认为block的推广可取代代理设计模式,其实block并不能取代代理,代理的模式可以让代码逻辑性更强,更整洁,也会有更高的可读性和可扩展性。相比之下,我觉得block更多的是取代了选择器@selector。
如果你有这个Controller中的view里面有IBOutlet的变量,如果你在A的地方进行赋值或者其他操作的话,界面将不会有任何更新,那些IBoutlet变量的值都为NULL, 如果在B处设置就可以正常显示了。
做一个实验,通过实验来分析viewController的生命周期。 和生命周期几个相关的方法 - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"FirstVC viewDidLoad"); } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear]; NSLog(@"FirstVC viewWillAppear"); } - (void)didRe
iOS的存储方式之一——属性列表plist,还是经常见到的,可以很方便的用来管理一些有序的批量数据,特别是用来显示固定的内容到表单上时,不需要在代码中反复地繁琐编写数组,而可以在plist属性列表中进行可视化操作,极为便捷,本文讲解如何创建和使用plist列表,并显示在表单上。
Apple 在 iOS4 中添加 addObserverForName 方法,给予开发者可以在block中处理 Notification 通知的便捷方法。
前言 今天有位群友抛出了一个很有意思的问题:为什么系统类的 class 地址比栈区变量更高? image-20210519235852843 iOS 进程内存布局 通常情况下,我们对进程内存的布局
前言 本文是我学习了onevcat的这篇转场入门做的一点笔记。 今天我们来实现一个简单的自定义转场,我们先来看看这篇文章将要实现的一个效果图吧: 过程详解 热身准备 我们先创建一个工程,首先
1. 控制器View的创建 首先我们来看一下控制器view创建的流程图 控制器view加载.jpeg 从图中我们可以看出,在控制器view加载过程中有两个重要的方法loadView和viewDidLo
本文首发于我的个人博客:『不羁阁』 https://bujige.net 文章链接:https://bujige.net/blog/iOS-Application-jump.html 这篇文章通过一步步指导,教你彻底学会『iOS应用间相互跳转』问题。文末有Github的学习Demo。 1. 应用间相互跳转简介 在iOS开发的过程中,我们经常会遇到需要从一个应用程序A跳转到另一个应用程序B的场景。这就需要我们掌握iOS应用程序之间的相互跳转知识。 下面来看看我们在开发过程中遇到的应用场景。 2.
iPhone下每个app可用的内存是被限制的,如果一个app使用的内存超过20M,则系统会向该app发送Memory Warning消息。收到此消息后,app必须正确处理,否则可能出错或者出现内存泄露。
iOS 14 中 UICollectionView 的功能继续增强,可以在一定程度上替换 UITableView。本文以一个案例的形式看看如何使用。
LLDB是个开源的内置于XCode的具有REPL(read-eval-print-loop)特征的Debugger,其可以安装C++或者Python插件。在日常的开发和调试过程中给开发人员带来了非常多的帮助。了解并熟练掌握LLDB的使用是非常有必要的。这篇文章将会带着大家一起了解在iOS开发中LLDB调试器的使用。
领取专属 10元无门槛券
手把手带您无忧上云