新手使用UICollectionController和UITableViewController使用容易造成的对象内存过早释放错误

比如添加UITableViewController的属性tableView

错误原因,属性设为Controller而不是View,Controller保持,View可能被释放


方法1是错的:
方法1:
.h文件
#import  "UITableViewController.h"
@property  ( retain , nonatomic UITableViewController  * tableViewController;
.m文件
self . tableViewController  = [[ UITableViewController   alloc ] init];
[ self . view   addSubview : self . tableViewController.tableView ];//
(注:这里出错,tableViewController为属性,不会被释放,反而需要保留的tableViewController.talbeView被释放。)


正确方法:
.h文件
@property  ( retain , nonatomic UITableView  * tableView;
.m文件
self . tableViewController  = [[ UITableViewController   alloc ] init];
self.tableView = self.tableViewController.tableView;
[ self . view   addSubview : self . tableViewController.tableView ];//
正确,保存了tableView。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值