ios - How do I transition to a different view controller programmatically? -
hey guys i'm trying app load new view when method called. within method have code:
viewcontroller *gameoverviewcontroller = [[viewcontroller alloc] init]; [self presentviewcontroller:gameoverviewcontroller animated:yes completion:nil];
which taken straight how switch views programmatically in viewcontroller? (xcode iphone).
anyways, when seek switch view controller called game view controller called gameoverviewcontroller ton of errors.
"unknown receiver 'viewcontroller'; did mean 'uiviewcontroller'
and app crashes. i'm doing wrong have no thought exactly. have declare gameoverviewcontroller in game.h or in appdelegate or something?
edit: both view controllers in same main.storyboard file if matters
the unknown receiver message means can't find class definition view controller class called viewcontroller
. name of class you're using "game over" view controller? , if so, have done #import "viewcontroller.h"
@ start of .m
file?
the fundamental problem cannot find class called viewcontroller
.
setting aside, don't instantiate new view controllers using alloc
, init
anymore, reply may have implied. technique used nibs (and worked if nib name matched class name).
for new developers, might encourage start storyboards. modern tutorial should walk through how utilize storyboards. (google "ios storyboard tutorial" , you'll lots of hits.)
if, example, storyboard has scene "storyboard identifier" of gameoverviewcontroller
, might programmatically instantiate , nowadays like:
uiviewcontroller *controller = [self.storyboard instantiateviewcontrollerwithidentifier:@"gameoverviewcontroller"]; [self presentviewcontroller:controller animated:yes completion:nil];
or, if storyboard had segue current scene next scene, you'd create sure segue had own storyboard identifier, e.g. gameoversegue
, , you'd perform so:
[self performseguewithidentifier:@"gameoversegue" sender:self];
but find introduction/tutorial on storyboards, stumbling through stack overflow answers not fruitful exercise.
for historical purposes, it's worth noting if using nibs, can utilize build referenced in question (but you'd have create sure (a) class name right; , (b) did #import
class header). , if destination nib had different name class, you'd have like:
uiviewcontroller *controller = [[nsbundle mainbundle] loadnibnamed:@"nibname" owner:self options:nil]`; [self presentviewcontroller:controller animated:yes completion:nil];
but academic unless you're using nibs. if using storyboards, utilize 1 of above patterns if need transition new scene programmatically.
ios objective-c uiviewcontroller
No comments:
Post a Comment