解决:IOS<5.0时viewDidAppear/viewWillAppear无法被调用

原因:

苹果的文档是这样描述的:

If the view belonging to a view controlleris added to a view hierarchy directly, the view controller will not receivethis message. If you insert or add a view to the view hierarchy, and it has aview controller, you should send the associated view controller this messagedirectly. Failing to send the view controller this message will prevent anyassociated animation from being displayed.

    实际情况中,在addSubview, presentModelviewController或者TabViewController中加载viewController时,viewDidAppear/viewWillAppear都是无法被调用的。(iphone)

解决:

     如果是pushViewController的情况,可以直接利用UINavigationControllerDelegate,这样

.h文件中:

<UINavigationControllerDelegate>

.m文件中:

   self.navigationController.delegate =self

-(void)navigationController:(UINavigationControlle*)

    navigationController willShowViewController:

    (UIViewController *)viewController animated:(BOOL)animated  

{    

    [viewController viewWillAppear:animated];

}

-(void)navigationController:(UINavigationControlle*) 

    navigationController didShowViewController:

    (UIViewController *)viewController animated:(BOOL)animated

{

    [viewController viewDidAppear:animated];

}

   

    

     

转载于:https://my.oschina.net/lvlove/blog/82264

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值