1

I have a very weird problem and has not been able to solve it yet.

This class is defined:

@interface EngineViewController : UIViewController
{
}
@property (nonatomic,readonly) IBOutlet GameView* vGameView;
@property (nonatomic,readonly) IBOutlet MainMenu* vMainMenu;
@property (nonatomic,readonly) IBOutlet CountryOverlay* vCountryOverlay;
@end

In init method I have this code:

if (![[NSBundle mainBundle] loadNibNamed:@"EngineViewController" owner:self options:nil])
{
    NSLog(@"Failed to load menu nib!");
    return NO;
}

// init
[self.view addSubview:vMainMenu];

The problem is, that vMainMenu is nil, vGameView is 0x1 and MainMenu class instance is assigned to vCountryOverlay (instead of vMainMenu).

Yes, in Xib, I have EngineViewController as File Owner and vMainMenu outlet set to UIView (MainMenu class) + other outlets not set.

I am out of ideas what to try. I tried to create an empty xib, set file owner to EngineViewController and set that vMainMenu outlet again. I have also tried to add a new "dummy" outlet property at the beginning. Tried to call loadNibNamed from a different part of the app, always the same.

But when I created a new, clean project, new nib, set owner, made a few outlets and did the same it worked just fine.

Why would loadNibNamed cause the first outlet to be set to 0x1 and "to offset" others, setting an instance which should be at the current outlet to the next one? Any idea what to try?

Thanks a lot!!

4

3 に答える 3

0

プロパティに対して次の宣言を試していただけませんか。

@property (nonatomic,retain) IBOutlet GameView* vGameView;
@property (nonatomic,retain) IBOutlet MainMenu* vMainMenu;
@property (nonatomic,retain) IBOutlet CountryOverlay* vCountryOverlay;
于 2012-06-03T20:08:19.830 に答える
0

UIViewController's default init method may be doing some screwy things. You should use

- (id) init {
   self = [self initWithNibNamed:@"EngineViewController" ....];
   if (self) { ... }
   return self;
}
于 2012-06-04T16:24:28.237 に答える
0

Ok. Problem was in the (gdb) debugger. It showed wrong data for wrong symbols. Data was loaded correctly to IBOutlets, crashing problem was somewhere else. Thanks a lot for trying to help me.

It these situations, try to use NSLog first. :P

于 2012-06-04T16:40:58.173 に答える