iphone开发之解决viewWillAppear失效
转自:http://linuxstuding.iteye.com/blog/1224399
你可曾遇到过viewWillAppear没有被调用到的情况
产生原因是用了UINavigationController.
将UINavigationController的view作为subview添加到了其他viewController的view中。
或者把UINavigationController添加到UITabbarController中了。
此时,NavigationController的stack里面的viewController就收不到-(void)viewWillAppear:(BOOL)animated;等4个方法的调用。
原因呢
Apple Docs state:
Warning: If the view belonging to a view controller is added to a view hierarchy directly, the view controller will not receive this message. If you insert or add a view to the view hierarchy, and it has a view controller, you should send the associated view controller this message directly. Failing to send the view controller this message will prevent any associated animation from being displayed.
不过后面的到4.0的文档就没有发现这样的文字描述了,但是还是没能够调用的到这样
只是添加的更复杂的文档,头晕晕看不下去了。
解决方法两种:
1,在导航控制器上层controller的viewWillAppear中显式调用viewWillAppear方法。
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[subNavCntlr viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[subNavCntlr viewWillDisappear:animated];
}
2,把导航控制器上层controller设为UINavigationController的delegate
nav.delegate = self;
@interface
RootViewController : UIViewController <UINavigationControllerDelegate> {
UINavigationController *navController;
}
- (void
)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL
)animated
{
[viewController viewWillAppear:animated];
} - (void
)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController animated:(BOOL
)animated
{
[viewController viewDidAppear:animated];
} 凑合着用吧,我喜欢第二种,不过我更喜欢干脆不再viewWillappear里做事情了。
iphone开发之解决viewWillAppear失效的更多相关文章
- iPhone开发常问的十个问题
iPhone开发常问的十个问题 前言 今天去stackoverflow.com上看了一下iPhone标签下排名最高的10个问题,将它们整理出来,希望这些常见问题能帮到一些iPhone开发的初学者.本来 ...
- iOS:iPad和iPhone开发的异同(UIPopoverController、UISplitViewController)
iPad和iPhone开发的异同 1.iPhone和iPad: niPhone是手机,iPad.iPad Mini是平板电脑 iPhone和iPad开发的区别 屏幕的尺寸 \分辨率 UI元素的排布 \ ...
- iPad开发(相对于iPhone开发时专有的API)
iPad开发 一.iPad开发简介 1.什么是iPad 一款苹果公司于2010年发布的平板电脑 定价介于苹果的智能手机iPhone和笔记本电脑产品之间 跟iPhone一样,搭载的是iOS操作系统 2. ...
- iPhone开发初探
本文是作者从一无所知到入门的知识学习过程,并结合自己在嵌入式开发的经验所写的技术总结文章,以供后来者学习. 苹果公司的iphone平台采用Object-c做为native language的开发,Ob ...
- j2ee5.0开发中jstl标签失效
尝试了下,对于Weblogic中的出现的错误,也是有效的! j2ee5.0开发中jstl标签失效 原因不详, 解决办法, 一:将.web.xml中 <web-app version=&quo ...
- iphone 开发中使用zbar时遇到的几个典型问题解决方法。
iphone 开发中使用zbar时遇到的几个典型问题解决方法. 在近期的一个ios项目中使用到了一个二维码扫描库(Qrcode)--ZBar, 期间遇到2个问题. 1. zbar下载后使用其l ...
- iPhone开发与cocos2d 经验谈
转CSDN jilongliang : 首先,对于一个完全没有mac开发经验,甚至从没摸过苹果系统的开发人员来说,首先就是要熟悉apple的那一套开发框架(含开发环境IDE.开发框架uikit,还有开 ...
- iOS开发UI篇—iPad和iPhone开发的比较
一.iPad简介 1.什么是iPad 一款苹果公司于2010年发布的平板电脑 定位介于苹果的智能手机iPhone和笔记本电脑产品之间 跟iPhone一样,搭载的是iOS操作系统 2.iPad的市场情况 ...
- iPad和iPhone开发区别
原文:http://mobile.51cto.com/iphone-273895.htm iPad与iPhone 开发区别详解是本文要介绍的内容,先来看看他们的区别. 1.首先我们先从官方发布的SDK ...
随机推荐
- SICK TiM561激光雷达的使用
TIM系列激光扫描传感器原理: 激光发射器发出激光脉冲,当激光碰到物体后,部分激光反射回激光接收器.通过计算发射/接收脉冲时间差,可以计算出距离值.激光扫描器连续不停的发射激光脉冲,由旋转的光学机构将 ...
- Arduino和C51开发DS1302时钟
技术:51单片机.Arduino.DS1302时钟.串口通信 概述 本文实现51单片机和Arduino串口实时显示时钟功能,让读者对DS1302能够更好的理解,这次功能也和上节课学到的串口通信运用 ...
- UVA - 10298 Power Strings (KMP求字符串循环节)
Description Problem D: Power Strings Given two strings a and b we define a*b to be their concatenati ...
- onActivityResult 传递数据
onActivityResult 传递数据 http://www.cnblogs.com/sipher/articles/2435078.html 如下图所示.当菜单项变多时,出现了垂直的滚动条,选项 ...
- (原)linux下caffe模型转tensorflow模型
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/7419352.html 参考网址: https://github.com/ethereon/caffe- ...
- blktrace + blkparse + btt 分析IO
blktrace是一款block层的trace工具,block层在IO路径上的位置: 一个IO的生命周期大约是: ● I/O enters block layer – it can be: – Rem ...
- Linux内核的ioctl函数学习
Linux内核的ioctl函数学习 来源:Linux公社 作者:Linux 我这里说的ioctl函数是在驱动程序里的,因为我不知道还有没有别的场合用到了ioctl, 所以就规定了我们讨论的范围.为什 ...
- Using 1-Wire device with Intel Galileo
Using 1-Wire device with Intel Galileo 3 Replies Many people have had trouble with getting 1-Wire de ...
- POJ 1486 Sorting Slides (KM)
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2831 Accepted: 1076 De ...
- opencv 中出现错误 -215:Assertion failed
cv2.error: OpenCV(4.0.1) D:\Build\OpenCV\opencv-4.0.1\modules\imgproc\src\color.cpp:181: error: (-21 ...