我正在使用 Xcode 4.4.1。当我定义 @property
喜欢UINavigationController
或NSArray
在 .h 文件中时,我必须@synthesize
在 .m 文件中定义它。但有些人@property
喜欢UITabBarController
或NSString
我不必@synthesize
让它发挥作用。
我的问题是什么@property
需要@synthesize
什么不需要。
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UITabBarController *_tabBar;
UINavigationController *_navBar;
}
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) Employee *empView;
@property (nonatomic, retain) UITabBarController *_tabBar;
@property (nonatomic, retain) UINavigationController *_navBar;
AppDelegate.m
@implementation AppDelegate
@synthesize _navBar;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
Employee *emp = [[Employee alloc]initWithNibName:@"Employee" bundle:nil];
self._tabBar = [[UITabBarController alloc]init];
self._navBar = [[UINavigationController alloc]initWithRootViewController:emp];
self._tabBar.viewControllers = [NSArray arrayWithObjects:_navBar, nil];
self.window.rootViewController = self._tabBar;
self._navBar.navigationBar.tintColor = [UIColor brownColor];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
当@synthesize
UINavigationController
我得到UINavigationController
and时UITabBarController
。但是当我不这样 做时,我@synthesize
UINavigationController
不会得到UINavigationController
但UITabBarController
会显示。
在这两种情况下我都没有@synthesize
UITabBarController
谢谢