开发者

References are null after synthesizing

开发者 https://www.devze.com 2023-04-05 07:44 出处:网络
I\'ve got a problem with this code. @class CatalogMenu; @class SettingsMenu; @interface TabBar : UIViewController {

I've got a problem with this code.

@class CatalogMenu;
@class SettingsMenu;

@interface TabBar : UIViewController {
    CatalogMenu *catalogMasterView;
    SettingsMenu *settingsMasterView;
}

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@property (nonatomic, retain) IBOutlet CatalogMenu *catalogMasterView;
@property (nonatomic, retain) IBOutlet SettingsMenu *settingsMasterView;

I got a UIViewController subclass, which implements the interface at the top. To use my classes in this UIViewController i've imported the two classes CatalogMenu and SettingsMenu. The problem is, that all the variables are null after 开发者_StackOverflow中文版synthesizing. That means, that they all got no address in the memory. The problem disappears if i change the subclass to NSObject. But this can't be the answer, because then i cant use the UIViewController functions. Is this a known problem?


Synthesizing doesn't actually allocate your variables which is why they are null, it just provides the Getter/Setter methods for accessing the variables. In your init method in the TabBar class you need to allocate your catalogMasterView and settingsMasterView

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号