gpt4 book ai didi

objective-c - IOS:默认属性值

转载 作者:行者123 更新时间:2023-11-28 20:37:41 31 4
gpt4 key购买 nike

如果我直接在实现文件中这样写:

UINavigationBar *navBar = [[UINavigationBar alloc] init];

在这种情况下,我没有为我的导航栏设置任何属性,它的属性/属性/无是什么。

编辑

-(IBAction) loginButtonPressed:(UIButton *)sender
{
UITabBarController *tabBar = [[UITabBarController alloc] init];
FirstScreen *f = [[FirstScreen alloc] initWithNibName:@"FirstScreen" bundle:nil];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:f];
nav1.title = @"FirstScreen";

SecondScreen *s = [[SecondScreen alloc] initWithNibName:@"SecondScreen" bundle:nil];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:s];
nav2.title = @"SecondScreen";

ThirdScreen *t = [[ThirdScreen alloc] initWithNibName:@"ThirdScreen" bundle:nil];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:t];
nav3.title = @"ThirdScreen";

NSArray *navControllers = [NSArray arrayWithObjects:f, s, t, nil];

tabBar.viewControllers = navControllers;

}

最佳答案

对象的属性默认为nil,或0。但是这些值可能已在 init 方法中更改。

更多信息,您可以随时咨询documentation :

  • tintColor : The default value is nil.

  • barStyle : The default value is UIBarStyleDefault.


编辑

要回答您编辑过的问题,tabBarnav2 ... 是局部变量而不是属性。

如果你想让它们成为属性,你必须先声明这样的属性,然后你必须使用 self.tabBar 访问,...

.h文件中:

// ...
@property (strong, nonatomic) UITabBarController *tabBar;
// ...

.m 文件中:

// ... @synthesize tabBar;

-(IBAction) loginButtonPressed:(UIButton *)sender
{
self.tabBar = [[UITabBarController alloc] init];
// ...
}

关于objective-c - IOS:默认属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9806885/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com