Swift PushViewController From A Different Storyboard [duplicate]
This question already has an answer here:
What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?
8 answers
iOS - Push viewController from code and storyboard
5 answers
I'm trying to show one of my ViewControllers
of a different storyboard programmatically. But for some reasons the properties of the ViewController
I'm trying to show are nil.
That's my error: Unexpectedly found nil while unwrapping an Optional value
I'm getting the error in my
SecondViewController
. It is showing but
my app crashes due to the properties being nil.
That's my code:
let secondStoryBoard = UIStoryboard(name: "SecondStoryBoard", bundle: nil)
let secondViewController = secondStoryBoard.instantiateViewController(withIdentifier: "secondVC") as! SecondVC
self.navigationController?.pushViewController(secondViewController, animated: true)
That's the code producing the error:
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
mapView.isHidden = true // ERROR!! Unexpectedly found nil while unwrapping an Optional value
}
SOLVED: just had to reconnect my
@IBOutlet
connections
swift uiviewcontroller uinavigationcontroller uistoryboard uistoryboardsegue
marked as duplicate by Robert Dresler, Sh_Khan
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 20:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?
8 answers
iOS - Push viewController from code and storyboard
5 answers
I'm trying to show one of my ViewControllers
of a different storyboard programmatically. But for some reasons the properties of the ViewController
I'm trying to show are nil.
That's my error: Unexpectedly found nil while unwrapping an Optional value
I'm getting the error in my
SecondViewController
. It is showing but
my app crashes due to the properties being nil.
That's my code:
let secondStoryBoard = UIStoryboard(name: "SecondStoryBoard", bundle: nil)
let secondViewController = secondStoryBoard.instantiateViewController(withIdentifier: "secondVC") as! SecondVC
self.navigationController?.pushViewController(secondViewController, animated: true)
That's the code producing the error:
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
mapView.isHidden = true // ERROR!! Unexpectedly found nil while unwrapping an Optional value
}
SOLVED: just had to reconnect my
@IBOutlet
connections
swift uiviewcontroller uinavigationcontroller uistoryboard uistoryboardsegue
marked as duplicate by Robert Dresler, Sh_Khan
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 20:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
I know what it means. I just don't know why I'm getting this error
– Marie.K
Dec 28 '18 at 19:59
add a comment |
This question already has an answer here:
What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?
8 answers
iOS - Push viewController from code and storyboard
5 answers
I'm trying to show one of my ViewControllers
of a different storyboard programmatically. But for some reasons the properties of the ViewController
I'm trying to show are nil.
That's my error: Unexpectedly found nil while unwrapping an Optional value
I'm getting the error in my
SecondViewController
. It is showing but
my app crashes due to the properties being nil.
That's my code:
let secondStoryBoard = UIStoryboard(name: "SecondStoryBoard", bundle: nil)
let secondViewController = secondStoryBoard.instantiateViewController(withIdentifier: "secondVC") as! SecondVC
self.navigationController?.pushViewController(secondViewController, animated: true)
That's the code producing the error:
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
mapView.isHidden = true // ERROR!! Unexpectedly found nil while unwrapping an Optional value
}
SOLVED: just had to reconnect my
@IBOutlet
connections
swift uiviewcontroller uinavigationcontroller uistoryboard uistoryboardsegue
This question already has an answer here:
What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?
8 answers
iOS - Push viewController from code and storyboard
5 answers
I'm trying to show one of my ViewControllers
of a different storyboard programmatically. But for some reasons the properties of the ViewController
I'm trying to show are nil.
That's my error: Unexpectedly found nil while unwrapping an Optional value
I'm getting the error in my
SecondViewController
. It is showing but
my app crashes due to the properties being nil.
That's my code:
let secondStoryBoard = UIStoryboard(name: "SecondStoryBoard", bundle: nil)
let secondViewController = secondStoryBoard.instantiateViewController(withIdentifier: "secondVC") as! SecondVC
self.navigationController?.pushViewController(secondViewController, animated: true)
That's the code producing the error:
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
mapView.isHidden = true // ERROR!! Unexpectedly found nil while unwrapping an Optional value
}
SOLVED: just had to reconnect my
@IBOutlet
connections
This question already has an answer here:
What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?
8 answers
iOS - Push viewController from code and storyboard
5 answers
swift uiviewcontroller uinavigationcontroller uistoryboard uistoryboardsegue
swift uiviewcontroller uinavigationcontroller uistoryboard uistoryboardsegue
edited Dec 28 '18 at 20:11
Marie.K
asked Dec 28 '18 at 19:51
Marie.KMarie.K
175
175
marked as duplicate by Robert Dresler, Sh_Khan
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 20:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Robert Dresler, Sh_Khan
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 20:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
I know what it means. I just don't know why I'm getting this error
– Marie.K
Dec 28 '18 at 19:59
add a comment |
I know what it means. I just don't know why I'm getting this error
– Marie.K
Dec 28 '18 at 19:59
I know what it means. I just don't know why I'm getting this error
– Marie.K
Dec 28 '18 at 19:59
I know what it means. I just don't know why I'm getting this error
– Marie.K
Dec 28 '18 at 19:59
add a comment |
1 Answer
1
active
oldest
votes
This means that the following line is either nil
or not of type SecondVC
.
secondStoryBoard.instantiateViewController(withIdentifier: "secondVC")
I would verify in your storyboard that you have an identifier secondVC
and that view controller is of type SecondVC
.
Edit:
Based on the new code the OP posted in the question, changing the SecondVC to the following should work.
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
mapView.isHidden = true
}
}
Basically this will wait until the view has loaded before accessing the mapView
. For the original code, you were trying to access mapView
before it has actually been loaded.
Edit 2:
It looks like mapView
outlet is not properly linked to the storyboard.
Thank you, I don't think I explained it enough. I edited my question
– Marie.K
Dec 28 '18 at 19:56
@Marie.K I don't understand your edit.It is showing but my app crashes due to the properties being nil.
. Which properties are nil? Can you show the line it's actually crashing on?
– Charlie Fish
Dec 28 '18 at 19:57
Sorry, I edited it again
– Marie.K
Dec 28 '18 at 19:59
1
@CharlieFish I think this is just a very common problem with bad connection ofIBOutlet
– Robert Dresler
Dec 28 '18 at 20:08
1
Okay, guys thank you I just disconnected and reconnected my IBOutlet. It works now
– Marie.K
Dec 28 '18 at 20:10
|
show 10 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This means that the following line is either nil
or not of type SecondVC
.
secondStoryBoard.instantiateViewController(withIdentifier: "secondVC")
I would verify in your storyboard that you have an identifier secondVC
and that view controller is of type SecondVC
.
Edit:
Based on the new code the OP posted in the question, changing the SecondVC to the following should work.
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
mapView.isHidden = true
}
}
Basically this will wait until the view has loaded before accessing the mapView
. For the original code, you were trying to access mapView
before it has actually been loaded.
Edit 2:
It looks like mapView
outlet is not properly linked to the storyboard.
Thank you, I don't think I explained it enough. I edited my question
– Marie.K
Dec 28 '18 at 19:56
@Marie.K I don't understand your edit.It is showing but my app crashes due to the properties being nil.
. Which properties are nil? Can you show the line it's actually crashing on?
– Charlie Fish
Dec 28 '18 at 19:57
Sorry, I edited it again
– Marie.K
Dec 28 '18 at 19:59
1
@CharlieFish I think this is just a very common problem with bad connection ofIBOutlet
– Robert Dresler
Dec 28 '18 at 20:08
1
Okay, guys thank you I just disconnected and reconnected my IBOutlet. It works now
– Marie.K
Dec 28 '18 at 20:10
|
show 10 more comments
This means that the following line is either nil
or not of type SecondVC
.
secondStoryBoard.instantiateViewController(withIdentifier: "secondVC")
I would verify in your storyboard that you have an identifier secondVC
and that view controller is of type SecondVC
.
Edit:
Based on the new code the OP posted in the question, changing the SecondVC to the following should work.
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
mapView.isHidden = true
}
}
Basically this will wait until the view has loaded before accessing the mapView
. For the original code, you were trying to access mapView
before it has actually been loaded.
Edit 2:
It looks like mapView
outlet is not properly linked to the storyboard.
Thank you, I don't think I explained it enough. I edited my question
– Marie.K
Dec 28 '18 at 19:56
@Marie.K I don't understand your edit.It is showing but my app crashes due to the properties being nil.
. Which properties are nil? Can you show the line it's actually crashing on?
– Charlie Fish
Dec 28 '18 at 19:57
Sorry, I edited it again
– Marie.K
Dec 28 '18 at 19:59
1
@CharlieFish I think this is just a very common problem with bad connection ofIBOutlet
– Robert Dresler
Dec 28 '18 at 20:08
1
Okay, guys thank you I just disconnected and reconnected my IBOutlet. It works now
– Marie.K
Dec 28 '18 at 20:10
|
show 10 more comments
This means that the following line is either nil
or not of type SecondVC
.
secondStoryBoard.instantiateViewController(withIdentifier: "secondVC")
I would verify in your storyboard that you have an identifier secondVC
and that view controller is of type SecondVC
.
Edit:
Based on the new code the OP posted in the question, changing the SecondVC to the following should work.
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
mapView.isHidden = true
}
}
Basically this will wait until the view has loaded before accessing the mapView
. For the original code, you were trying to access mapView
before it has actually been loaded.
Edit 2:
It looks like mapView
outlet is not properly linked to the storyboard.
This means that the following line is either nil
or not of type SecondVC
.
secondStoryBoard.instantiateViewController(withIdentifier: "secondVC")
I would verify in your storyboard that you have an identifier secondVC
and that view controller is of type SecondVC
.
Edit:
Based on the new code the OP posted in the question, changing the SecondVC to the following should work.
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
mapView.isHidden = true
}
}
Basically this will wait until the view has loaded before accessing the mapView
. For the original code, you were trying to access mapView
before it has actually been loaded.
Edit 2:
It looks like mapView
outlet is not properly linked to the storyboard.
edited Dec 28 '18 at 20:10
answered Dec 28 '18 at 19:54
Charlie FishCharlie Fish
5,48842972
5,48842972
Thank you, I don't think I explained it enough. I edited my question
– Marie.K
Dec 28 '18 at 19:56
@Marie.K I don't understand your edit.It is showing but my app crashes due to the properties being nil.
. Which properties are nil? Can you show the line it's actually crashing on?
– Charlie Fish
Dec 28 '18 at 19:57
Sorry, I edited it again
– Marie.K
Dec 28 '18 at 19:59
1
@CharlieFish I think this is just a very common problem with bad connection ofIBOutlet
– Robert Dresler
Dec 28 '18 at 20:08
1
Okay, guys thank you I just disconnected and reconnected my IBOutlet. It works now
– Marie.K
Dec 28 '18 at 20:10
|
show 10 more comments
Thank you, I don't think I explained it enough. I edited my question
– Marie.K
Dec 28 '18 at 19:56
@Marie.K I don't understand your edit.It is showing but my app crashes due to the properties being nil.
. Which properties are nil? Can you show the line it's actually crashing on?
– Charlie Fish
Dec 28 '18 at 19:57
Sorry, I edited it again
– Marie.K
Dec 28 '18 at 19:59
1
@CharlieFish I think this is just a very common problem with bad connection ofIBOutlet
– Robert Dresler
Dec 28 '18 at 20:08
1
Okay, guys thank you I just disconnected and reconnected my IBOutlet. It works now
– Marie.K
Dec 28 '18 at 20:10
Thank you, I don't think I explained it enough. I edited my question
– Marie.K
Dec 28 '18 at 19:56
Thank you, I don't think I explained it enough. I edited my question
– Marie.K
Dec 28 '18 at 19:56
@Marie.K I don't understand your edit.
It is showing but my app crashes due to the properties being nil.
. Which properties are nil? Can you show the line it's actually crashing on?– Charlie Fish
Dec 28 '18 at 19:57
@Marie.K I don't understand your edit.
It is showing but my app crashes due to the properties being nil.
. Which properties are nil? Can you show the line it's actually crashing on?– Charlie Fish
Dec 28 '18 at 19:57
Sorry, I edited it again
– Marie.K
Dec 28 '18 at 19:59
Sorry, I edited it again
– Marie.K
Dec 28 '18 at 19:59
1
1
@CharlieFish I think this is just a very common problem with bad connection of
IBOutlet
– Robert Dresler
Dec 28 '18 at 20:08
@CharlieFish I think this is just a very common problem with bad connection of
IBOutlet
– Robert Dresler
Dec 28 '18 at 20:08
1
1
Okay, guys thank you I just disconnected and reconnected my IBOutlet. It works now
– Marie.K
Dec 28 '18 at 20:10
Okay, guys thank you I just disconnected and reconnected my IBOutlet. It works now
– Marie.K
Dec 28 '18 at 20:10
|
show 10 more comments
I know what it means. I just don't know why I'm getting this error
– Marie.K
Dec 28 '18 at 19:59