我最近阅读了一篇关于不再需要在 ViewControllers 上声明 ivars 和属性的帖子,并且在我注意到它们时一直在从我的代码中删除重复的声明。
我注意到的一个非常令人费解的效果是,如果属性缺少声明的 ivar,则需要在其前面加上self.
Eg:
自定义VC.h:
@interface CustomVC : UIViewController <UITableViewDelegate,UITableViewDataSource> {
...
@property (nonatomic, strong) IBOutlet UITableView *itemsTableView;
自定义VC.m:
[itemsTableView reloadData]; // cellForRowAtIndexPath not called
[self.itemsTableView reloadData]; // table view refreshed as expected
如果在没有 的情况下访问变量时出现问题self.
,我预计会出现编译时或运行时错误,但它似乎只是默默地失败,使得调试变得困难。