UIViewController subclass can't assign instance variable

萝らか妹 提交于 2019-11-28 01:33:37

Ok, I figured out the problem. I'm using Xcode 4.3, which is supposed to allow you to use the lldb debugger with iOS (or so Apple says). My problem went away when I changed the debugger to GDB. Though now I have a useful debugger, I've realized that the assignments were actually working correctly. The debugger was just spitting back the incorrect data. Gotta love it.

My advice: Don't use lldb on iOS. Even though Apple says the lldb debugger can be used with iOS, it's still not stable enough to rely on. So yeah, there went 6 hours of my life....

I've filed a bug with Apple: 10945570

UPDATE

Apple seems to have fixed this in Xcode 4.3.1. At least, so far LLDB is working well for me.

UPDATE 2

No, nevermind, LLDB is still messed up in the simulator.

UPDATE 3

So far as I can tell, this issue is now resolved in 4.3.2. I've been using the LLDB debugger now for about a week and I haven't had any problems with it giving me garbage values.

Peter M

This code does not seem correct:

@interface SplitViewController : UIViewController

@property (strong) UIViewController *leftViewController;
@property (strong) UIViewController *rightViewController;
@end

....

@implementation SplitViewController{
  BOOL _showLeftPane;
  UIViewController *_rightNavController;
  UIViewController *_leftNavController;
}

Is this what you really have? Because I would have expected something like this in the .h:

@interface SplitViewController : UIViewController
@property BOOL showLeftPane;
@property (strong) UIViewController* leftViewController;
@property (strong) UIViewController* rightViewController;
@end

And in the .m

@implementation SplitViewController
@synthesize showLeftPane;
@synthesize leftViewController;
@synthesize rightViewController;
...
@end

Or if you wanted to use explicit backing vars

@interface SplitViewController : UIViewController
{
    BOOL _showLeftPane;
    UIViewController* _leftViewController;
    UIViewController* _rightViewController;
}

@property BOOL showLeftPane;
@property (strong) UIViewController* leftViewController;
@property (strong) UIViewController* rightViewController;
@end

....

@implementation SplitViewController
@synthesize showLeftPane = _showLeftPane;
@synthesize leftViewController = _leftViewController;
@synthesize rightViewController = _rightViewController;
...
@end

From the posted code it looks like you are mixing up concepts between the @interface and the @implementation

As per the your comment, if you want private vars then the .m file should be something like:

@interface SplitViewController()
{
  BOOL showLeftPane;
  UIViewController* leftViewController;
  UIViewController* rightViewController;
}
@end

....

@implementation SplitViewController
...
@end

Actually I'll probably take that back. Not sure it works for vars .. but it does for methods.

YOu can make vars private through the use of @private in the interface

edit

My mistake. The original code is correct, in that you can put iVars in the implementation file like that since XCode 4.2. As per this SO question instance-variables-declared-in-objc-implementation-file you need 4.2+ and LLVM selected.

So now I sound like I don't know what I am talking about!

Maybe for some reason the #import <UIKit/UIKit.h> is not on your precompiled headers, try adding it there, or simply adding the import on top of your file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!