ios - 具有默认值的 Objective C UIViewController 属性

标签 ios objective-c

我有一个 UIViewController (iOS) 具有从创建它的 View 设置的 bool 属性。

我可以为属性设置默认值吗?

如果我把它放在 ViewDidLoad即使我在推送 ViewController 之前将值设置为不同的值,它也会被调用

@Erakk 要求找出问题的一些代码:

@implementation CreateMomentViewController

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
{
    // NOT GETTING EXECUTED
    CreateMomentViewController *me = [super initWithNibName:nibName bundle:nibBundle];
    me.exitButton = YES;
    return me;
}
- (void)viewDidLoad {
    [super viewDidLoad];

//    self.exitButton = YES;
    // Do any additional setup after loading the view.
}

调用者,召集者:
ChefSelectionViewControllerCreateMomentViewController 的子类
ChefSelectionViewController *nextScreen = [self.storyboard instantiateViewControllerWithIdentifier:@"ChefSelect"];
dispatch_async(dispatch_get_main_queue(), ^{
    [self.navigationController pushViewController:nextScreen animated:YES];
});

最佳答案

尝试将您的 initWithNibName 更改为:

- (id)initWithCoder:(NSCoder *)decoder
{
    self = [super initWithCoder:decoder];
    if (self) {
        self.exitButton = YES;
    }
    return self;
}

另外,我认为您不需要 viewController 的子类来创建它,但我不知道您的流程是如何工作的,所以它只是一个评论 =)

顺便说一句,您正在以 @"ChefSelect" 的名称实例化 View ,它的类(在 xib/界面生成器中)应该与 CreateMomentViewController 相同.您可能正在实例化 ChefSelectionViewController和你的代码 CreateMomentsViewController永远不会被调用。

关于ios - 具有默认值的 Objective C UIViewController 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30577494/

相关文章:

objective-c - SOAP WebService objective-c

objective-c - 如何向 MacOS Finder 添加自定义列?

ios - SceneKit unproject 一个点给出了奇怪的结果

objective-c - 更改 UICollectionViewLayout 时检测隐式动画的结束

ios - 如何重新加载具有不同行数的 UITableView 部分?

ios - 无法删除被拒绝的 IAP

ios - Swift:如何在 cellForRowAtIndexPath 方法中设置 UITableViewCell

IOS无论如何在整个应用程序中都有NSAttributedString。 swift

ios - Zombie UIWebView 在从 javascript 调用 alert() 后立即解除分配

objective-c - 双括号方法语法。