Sunday, 15 September 2013

objective c - How to switch View Controllers in iOS? -



objective c - How to switch View Controllers in iOS? -

i've looked on google & stack overflow, haven't found 1 clear answer. how switch tocviewcontroller after tapping uibutton? i'm using "presentviewcontroller" freezes on tapping button. in advance help.

#import "splashloginviewcontroller.h" #import <quartzcore/quartzcore.h> #import "tocviewcontroller.h" @interface splashloginviewcontroller () @end @implementation splashloginviewcontroller - (void) displaytoc { tocviewcontroller *toc = [[tocviewcontroller alloc] init]; [self presentviewcontroller:toc animated:yes completion:nil]; } - (void)initializesplashview { uiview *backgroundview = [[uiview alloc] initwithframe:cgrectmake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)]; backgroundview.backgroundcolor = [uicolor colorwithred:52.0/255.0 green:170.0/255.0 blue:220.0/255.0 alpha:1.0]; backgroundview.tag = 1; backgroundview.layer.zposition = 99.0f; [self.view addsubview:backgroundview]; uilabel *codeworkslabelview = [[uilabel alloc] initwithframe:cgrectmake(self.view.bounds.size.width, self.view.bounds.size.height / 2.0 - 25.0, self.view.bounds.size.width, 50.0)]; codeworkslabelview.text = @"codeworks"; codeworkslabelview.textalignment = nstextalignmentcenter; codeworkslabelview.textcolor = [uicolor whitecolor]; codeworkslabelview.font = [uifont fontwithname:@"montserrat" size:30.0]; codeworkslabelview.tag = 2; codeworkslabelview.layer.zposition = 100.0f; [self.view addsubview:codeworkslabelview]; } - (void)initializeloginview { cgrect loginframe = cgrectmake(50.0, 100.0, self.view.bounds.size.width - 100.0, 30.0); cgrect passwordframe = cgrectmake(50.0, 180.0, self.view.bounds.size.width - 100.0, 30.0); uitextfield *usernameinput = [[uitextfield alloc] init]; usernameinput.frame = loginframe; usernameinput.placeholder = @"username"; usernameinput.font = [uifont fontwithname:@"montserrat" size:15.0]; usernameinput.returnkeytype = uireturnkeynext; usernameinput.tag = 3; usernameinput.autocorrectiontype = uitextautocorrectiontypeno; uitextfield *passwordinput = [[uitextfield alloc] init]; passwordinput.frame = passwordframe; passwordinput.placeholder = @"password"; passwordinput.font = [uifont fontwithname:@"montserrat" size:15.0]; passwordinput.returnkeytype = uireturnkeydone; passwordinput.tag = 4; passwordinput.securetextentry = yes; calayer *bottomborder = [calayer layer]; bottomborder.frame = cgrectmake(0.0, 29.0, usernameinput.frame.size.width, 1.0); bottomborder.backgroundcolor = [uicolor blackcolor].cgcolor; calayer *bordercopy = [calayer layer]; bordercopy.frame = cgrectmake(0.0, 29.0, passwordinput.frame.size.width, 1.0); bordercopy.backgroundcolor = [uicolor blackcolor].cgcolor; [usernameinput.layer addsublayer:bottomborder]; [passwordinput.layer addsublayer:bordercopy]; [self.view addsubview:usernameinput]; [self.view addsubview:passwordinput]; uilabel *signinbutton = [[uilabel alloc] initwithframe:cgrectmake(0, 270, self.view.bounds.size.width, 60.0)]; signinbutton.font = [uifont fontwithname:@"montserrat" size:15.0]; signinbutton.text = @"sign in"; signinbutton.textcolor = [uicolor blackcolor]; signinbutton.tag = 5; signinbutton.textalignment = nstextalignmentcenter; calayer *topbuttonborder = [calayer layer]; topbuttonborder.frame = cgrectmake(0, 0, self.view.bounds.size.width, 1); topbuttonborder.backgroundcolor = [uicolor blackcolor].cgcolor; calayer *bottombuttonborder = [calayer layer]; bottombuttonborder.frame = cgrectmake(0, 59, self.view.bounds.size.width, 1); bottombuttonborder.backgroundcolor = [uicolor blackcolor].cgcolor; [signinbutton.layer addsublayer:topbuttonborder]; [signinbutton.layer addsublayer:bottombuttonborder]; [self.view addsubview:signinbutton]; uiview *optionsdivide = [[uiview alloc] initwithframe:cgrectmake(self.view.bounds.size.width / 2 - 0.5, self.view.bounds.size.height - 45, 1, 20)]; optionsdivide.backgroundcolor = [uicolor blackcolor]; [self.view addsubview:optionsdivide]; uibutton *tos = [uibutton buttonwithtype:uibuttontyperoundedrect]; uibutton *pp = [uibutton buttonwithtype:uibuttontyperoundedrect]; tos.frame = cgrectmake(self.view.bounds.size.width / 2 - 115.5 , self.view.bounds.size.height - 65, 110, 60); pp.frame = cgrectmake(self.view.bounds.size.width / 2 + 0.5 , self.view.bounds.size.height - 65, 110, 60); [tos settitle:@"terms of service" forstate:uicontrolstatenormal]; [pp settitle:@"privacy policy" forstate:uicontrolstatenormal]; pp.titlelabel.textalignment = nstextalignmentleft; tos.titlelabel.font = [uifont fontwithname:@"helveticaneue" size:12.0]; pp.titlelabel.font = [uifont fontwithname:@"helveticaneue" size:12.0]; [tos addtarget:self action:@selector(displaytoc:) forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:tos]; [self.view addsubview:pp]; } - (void)animatesplashscreen { [uiview animatewithduration:1.0 delay:0.0 options:uiviewanimationoptioncurveeaseinout animations:^{ [self.view viewwithtag:2].frame = cgrectmake(0.0, self.view.bounds.size.height / 2.0 - 25.0, self.view.bounds.size.width, 50.0); } completion:^(bool finished){ [self initializeloginview]; [uiview animatewithduration:0.5 delay:1.0 options:uiviewanimationoptioncurveeaseout animations:^{ [self.view viewwithtag:1].frame = cgrectmake(0.0, 0.0, self.view.bounds.size.width, 65.0); [self.view viewwithtag:2].frame = cgrectmake(0.0, 15.0, self.view.bounds.size.width, 50.0); ((uilabel *)[self.view viewwithtag:2]).transform = cgaffinetransformscale(((uilabel *)[self.view viewwithtag:2]).transform, 0.6, 0.6); } completion:^(bool finished){ ((uilabel *)[self.view viewwithtag:2]).font = [uifont fontwithname:@"montserrat" size:30.0]; }]; }]; } - (void)viewdidload { [super viewdidload]; [self initializesplashview]; } - (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; [self animatesplashscreen]; } - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { //cgpoint locationpoint = [[touches anyobject] locationinview:self.view]; //cgpoint viewpoint = [[self.view viewwithtag:5] convertpoint:locationpoint fromview:self.view]; //if ([[self.view viewwithtag:5] pointinside:viewpoint withevent:event]) { // [self.view viewwithtag:5].frame = cgrectmake(self.view.bounds.size.width / 2 - 62.5, 254.5, 130.0, 60.0); //} } - (void)touchesended:(nsset *)touches withevent:(uievent *)event { //[self.view viewwithtag:5].frame = cgrectmake(self.view.bounds.size.width / 2 - 67.5, 249.5, 130.0, 60.0); } - (void)touchescancelled:(nsset *)touches withevent:(uievent *)event { //[self.view viewwithtag:5].frame = cgrectmake(self.view.bounds.size.width / 2 - 67.5, 249.5, 130.0, 60.0); } - (void)didreceivememorywarning { [super didreceivememorywarning]; } @end

i copy-pasted code file , found warning on line [tos addtarget:self action:@selector(displaytoc:) forcontrolevents:uicontroleventtouchupinside]; warning says,

undeclared selector 'displaytoc:'

when ran code , tapped toc button, didn't freeze, crashed error:

-[viewcontroller displaytoc:]: unrecognized selector sent instance ...

these should strong hints on wrong in code. when inquire people code, should reveal , warnings, , crashes.

note, method named displaytoc not same method named displaytoc:

by way, animation did cool. job!

ios objective-c

No comments:

Post a Comment