【发布时间】:2012-03-31 12:31:42
【问题描述】:
我最近阅读了一篇关于不再需要在 ViewControllers 上声明 ivars 和属性的帖子,并且我注意到它们已经从我的代码中删除了重复的声明。
我注意到一个非常令人费解的效果是,如果属性缺少声明的 ivar,则需要在其前面加上 self. 例如:
CustomVC.h:
@interface CustomVC : UIViewController <UITableViewDelegate,UITableViewDataSource> {
...
@property (nonatomic, strong) IBOutlet UITableView *itemsTableView;
CustomVC.m:
[itemsTableView reloadData]; // cellForRowAtIndexPath not called
[self.itemsTableView reloadData]; // table view refreshed as expected
如果在没有self. 的情况下访问变量时出现问题,我预计会出现编译时或运行时错误,但它似乎只是默默地失败,因此难以调试。
【问题讨论】:
标签: objective-c ios properties ivar