IBOutlet nil - button











up vote
-2
down vote

favorite












I have a HomeController and a registerController. The HomeController is embedded in a navigation controller and is the root view controller. If I present the registerController modally in HomeController's ViewWillAppear:



let reg = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController
reg.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
reg.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
reg.view.frame = self.view.frame
self.view.addSubview(reg.view)


There is no problem. BUT if I present it by pushing it on the navigation controller stack:



let v = RegisterController()
self.navigationController?.pushViewController(v, animated: true)


the app crashes and says the IBOutlet for the signUp button (which is in registerController) is nil. I've re-created the outlet and cleaned the project and restarted xcode and nothing has worked...










share|improve this question
























  • Can you post your viewWillAppear code here?
    – iOS_Maccus
    Nov 20 at 6:27










  • @HPM the first snippet of code is my VWA. that's the only code in it
    – user7804097
    Nov 20 at 6:29






  • 1




    Matt answered your question check it
    – iOS_Maccus
    Nov 20 at 6:31















up vote
-2
down vote

favorite












I have a HomeController and a registerController. The HomeController is embedded in a navigation controller and is the root view controller. If I present the registerController modally in HomeController's ViewWillAppear:



let reg = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController
reg.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
reg.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
reg.view.frame = self.view.frame
self.view.addSubview(reg.view)


There is no problem. BUT if I present it by pushing it on the navigation controller stack:



let v = RegisterController()
self.navigationController?.pushViewController(v, animated: true)


the app crashes and says the IBOutlet for the signUp button (which is in registerController) is nil. I've re-created the outlet and cleaned the project and restarted xcode and nothing has worked...










share|improve this question
























  • Can you post your viewWillAppear code here?
    – iOS_Maccus
    Nov 20 at 6:27










  • @HPM the first snippet of code is my VWA. that's the only code in it
    – user7804097
    Nov 20 at 6:29






  • 1




    Matt answered your question check it
    – iOS_Maccus
    Nov 20 at 6:31













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I have a HomeController and a registerController. The HomeController is embedded in a navigation controller and is the root view controller. If I present the registerController modally in HomeController's ViewWillAppear:



let reg = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController
reg.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
reg.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
reg.view.frame = self.view.frame
self.view.addSubview(reg.view)


There is no problem. BUT if I present it by pushing it on the navigation controller stack:



let v = RegisterController()
self.navigationController?.pushViewController(v, animated: true)


the app crashes and says the IBOutlet for the signUp button (which is in registerController) is nil. I've re-created the outlet and cleaned the project and restarted xcode and nothing has worked...










share|improve this question















I have a HomeController and a registerController. The HomeController is embedded in a navigation controller and is the root view controller. If I present the registerController modally in HomeController's ViewWillAppear:



let reg = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController
reg.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
reg.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
reg.view.frame = self.view.frame
self.view.addSubview(reg.view)


There is no problem. BUT if I present it by pushing it on the navigation controller stack:



let v = RegisterController()
self.navigationController?.pushViewController(v, animated: true)


the app crashes and says the IBOutlet for the signUp button (which is in registerController) is nil. I've re-created the outlet and cleaned the project and restarted xcode and nothing has worked...







swift uinavigationcontroller uibutton iboutlet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 6:37

























asked Nov 20 at 6:24









user7804097

83110




83110












  • Can you post your viewWillAppear code here?
    – iOS_Maccus
    Nov 20 at 6:27










  • @HPM the first snippet of code is my VWA. that's the only code in it
    – user7804097
    Nov 20 at 6:29






  • 1




    Matt answered your question check it
    – iOS_Maccus
    Nov 20 at 6:31


















  • Can you post your viewWillAppear code here?
    – iOS_Maccus
    Nov 20 at 6:27










  • @HPM the first snippet of code is my VWA. that's the only code in it
    – user7804097
    Nov 20 at 6:29






  • 1




    Matt answered your question check it
    – iOS_Maccus
    Nov 20 at 6:31
















Can you post your viewWillAppear code here?
– iOS_Maccus
Nov 20 at 6:27




Can you post your viewWillAppear code here?
– iOS_Maccus
Nov 20 at 6:27












@HPM the first snippet of code is my VWA. that's the only code in it
– user7804097
Nov 20 at 6:29




@HPM the first snippet of code is my VWA. that's the only code in it
– user7804097
Nov 20 at 6:29




1




1




Matt answered your question check it
– iOS_Maccus
Nov 20 at 6:31




Matt answered your question check it
– iOS_Maccus
Nov 20 at 6:31












1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










It’s not a “bug”. Your code is what’s at fault. It has nothing to do with pushing vs presenting. It’s that this line is wrong:



let v = RegisterController()


That creates a barebones view controller with no outlets hooked up. The outlets are hooked up in the storyboard instance of this class. Create the view controller from the storyboard as you did in the first code, and all will be well.



let v = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController





share|improve this answer





















  • Thanks for the quick answer, I'll give it a try. But I'm using this same code (let v = HTPController() ) in the same file for HTPController and it works as expected though. It also has a button. What is wrong about this specific one?
    – user7804097
    Nov 20 at 6:32










  • @user7804097 That button probably isn't connected either. HTPController doesn't crash because you have not used that button in viewDidAppear or viewDidLoad. Try pressing that button, it shouldn't do what it is supposed to do.
    – Sweeper
    Nov 20 at 6:34










  • @user7804097 It simply is impossible.
    – Desdenova
    Nov 20 at 6:35










  • Thanks for the explanation everyone. That makes perfect sense! I can't accept for another 3 minutes
    – user7804097
    Nov 20 at 6:38













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387373%2fiboutlet-nil-button%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










It’s not a “bug”. Your code is what’s at fault. It has nothing to do with pushing vs presenting. It’s that this line is wrong:



let v = RegisterController()


That creates a barebones view controller with no outlets hooked up. The outlets are hooked up in the storyboard instance of this class. Create the view controller from the storyboard as you did in the first code, and all will be well.



let v = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController





share|improve this answer





















  • Thanks for the quick answer, I'll give it a try. But I'm using this same code (let v = HTPController() ) in the same file for HTPController and it works as expected though. It also has a button. What is wrong about this specific one?
    – user7804097
    Nov 20 at 6:32










  • @user7804097 That button probably isn't connected either. HTPController doesn't crash because you have not used that button in viewDidAppear or viewDidLoad. Try pressing that button, it shouldn't do what it is supposed to do.
    – Sweeper
    Nov 20 at 6:34










  • @user7804097 It simply is impossible.
    – Desdenova
    Nov 20 at 6:35










  • Thanks for the explanation everyone. That makes perfect sense! I can't accept for another 3 minutes
    – user7804097
    Nov 20 at 6:38

















up vote
3
down vote



accepted










It’s not a “bug”. Your code is what’s at fault. It has nothing to do with pushing vs presenting. It’s that this line is wrong:



let v = RegisterController()


That creates a barebones view controller with no outlets hooked up. The outlets are hooked up in the storyboard instance of this class. Create the view controller from the storyboard as you did in the first code, and all will be well.



let v = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController





share|improve this answer





















  • Thanks for the quick answer, I'll give it a try. But I'm using this same code (let v = HTPController() ) in the same file for HTPController and it works as expected though. It also has a button. What is wrong about this specific one?
    – user7804097
    Nov 20 at 6:32










  • @user7804097 That button probably isn't connected either. HTPController doesn't crash because you have not used that button in viewDidAppear or viewDidLoad. Try pressing that button, it shouldn't do what it is supposed to do.
    – Sweeper
    Nov 20 at 6:34










  • @user7804097 It simply is impossible.
    – Desdenova
    Nov 20 at 6:35










  • Thanks for the explanation everyone. That makes perfect sense! I can't accept for another 3 minutes
    – user7804097
    Nov 20 at 6:38















up vote
3
down vote



accepted







up vote
3
down vote



accepted






It’s not a “bug”. Your code is what’s at fault. It has nothing to do with pushing vs presenting. It’s that this line is wrong:



let v = RegisterController()


That creates a barebones view controller with no outlets hooked up. The outlets are hooked up in the storyboard instance of this class. Create the view controller from the storyboard as you did in the first code, and all will be well.



let v = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController





share|improve this answer












It’s not a “bug”. Your code is what’s at fault. It has nothing to do with pushing vs presenting. It’s that this line is wrong:



let v = RegisterController()


That creates a barebones view controller with no outlets hooked up. The outlets are hooked up in the storyboard instance of this class. Create the view controller from the storyboard as you did in the first code, and all will be well.



let v = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "signup") as! RegisterController






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 6:28









matt

322k45519719




322k45519719












  • Thanks for the quick answer, I'll give it a try. But I'm using this same code (let v = HTPController() ) in the same file for HTPController and it works as expected though. It also has a button. What is wrong about this specific one?
    – user7804097
    Nov 20 at 6:32










  • @user7804097 That button probably isn't connected either. HTPController doesn't crash because you have not used that button in viewDidAppear or viewDidLoad. Try pressing that button, it shouldn't do what it is supposed to do.
    – Sweeper
    Nov 20 at 6:34










  • @user7804097 It simply is impossible.
    – Desdenova
    Nov 20 at 6:35










  • Thanks for the explanation everyone. That makes perfect sense! I can't accept for another 3 minutes
    – user7804097
    Nov 20 at 6:38




















  • Thanks for the quick answer, I'll give it a try. But I'm using this same code (let v = HTPController() ) in the same file for HTPController and it works as expected though. It also has a button. What is wrong about this specific one?
    – user7804097
    Nov 20 at 6:32










  • @user7804097 That button probably isn't connected either. HTPController doesn't crash because you have not used that button in viewDidAppear or viewDidLoad. Try pressing that button, it shouldn't do what it is supposed to do.
    – Sweeper
    Nov 20 at 6:34










  • @user7804097 It simply is impossible.
    – Desdenova
    Nov 20 at 6:35










  • Thanks for the explanation everyone. That makes perfect sense! I can't accept for another 3 minutes
    – user7804097
    Nov 20 at 6:38


















Thanks for the quick answer, I'll give it a try. But I'm using this same code (let v = HTPController() ) in the same file for HTPController and it works as expected though. It also has a button. What is wrong about this specific one?
– user7804097
Nov 20 at 6:32




Thanks for the quick answer, I'll give it a try. But I'm using this same code (let v = HTPController() ) in the same file for HTPController and it works as expected though. It also has a button. What is wrong about this specific one?
– user7804097
Nov 20 at 6:32












@user7804097 That button probably isn't connected either. HTPController doesn't crash because you have not used that button in viewDidAppear or viewDidLoad. Try pressing that button, it shouldn't do what it is supposed to do.
– Sweeper
Nov 20 at 6:34




@user7804097 That button probably isn't connected either. HTPController doesn't crash because you have not used that button in viewDidAppear or viewDidLoad. Try pressing that button, it shouldn't do what it is supposed to do.
– Sweeper
Nov 20 at 6:34












@user7804097 It simply is impossible.
– Desdenova
Nov 20 at 6:35




@user7804097 It simply is impossible.
– Desdenova
Nov 20 at 6:35












Thanks for the explanation everyone. That makes perfect sense! I can't accept for another 3 minutes
– user7804097
Nov 20 at 6:38






Thanks for the explanation everyone. That makes perfect sense! I can't accept for another 3 minutes
– user7804097
Nov 20 at 6:38




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387373%2fiboutlet-nil-button%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin