UIAlertView in AppDelegate have to call Method in ViewController

Joined
May 18, 2012
Messages
5
Reaction score
0
Points
1
Hi,

i have a method called perform4 in the ViewController.m

Code:
-(void) perform4
{
 NSLog(@"perform4");
 UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
ViewController4 *view4 = (ViewController4 *) [mainStoryBoard instantiateViewControllerWithIdentifier:@"ViewController4"];

[self.view removeFromSuperview];
[self release];

self.view = view4.view;
[self release];
}

this Method has to be called from my AppDelegate.m with this AlertView Button

Code:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
 if(buttonIndex==0)
{
   NSLog(@"Button 0");

  
  //EVERYTHING I WILL PUT HERE DO NOT WORK OR MAKE A CRASH :/
  //like
  // ViewController *view1 = [[ViewController alloc]init];
  // [view1 perform4];
  // WHY DO THIS DONT WORK? 

}

Thanks
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
Your code is very confusing, I haven't used storyboards myself yet, so I will have accept your storyboard code is correct.

But to start with you are missing a curly brace in the second code snippet, try indenting your
code sections, so that you can see the different curly braces line up like this.

Code:
- (void)myMethod
{
	if (thisIsTrue) {
	
	}
}

Secondly you are releasing yourself twice in the first code snippet for some reason.

Sorry I can't help you much with this at the moment, but your code is very confusing, you
may have to be more specific with the details of your class files, and how they interact.

Regards Mark
 
OP
P
Joined
May 18, 2012
Messages
5
Reaction score
0
Points
1
thanks, but this isn't what i asked for, i need only to load ViewController4 :/ but how ?
 
OP
P
Joined
May 18, 2012
Messages
5
Reaction score
0
Points
1
it works, when i call it from the viewcontroller.m , but not when i try to call it from the appdelegate.m - i need to know how to call it, to make everything work :(

can you help me please?


ok i realized this with

Code:
self.window.rootViewController.view = view4;
[self.window makeKeyAndVisible];

but i have now the problem to switch back, while

Code:
self.window.rootViewController.view = view;
[self.window makeKeyAndVisible];

let crash my app :(
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
You still have'nt explained how the different class files interact in your project, so where
only going to be guessing here, also your mixing dot notation with square bracket synatx,
also you seem to have an ivar or property called view, you should probably change this to
another as it might be causing a conflict with your view controllers and windows own
properties also called view.

Try writing it this way and see what happens.

Code:
[[self window] setRootViewController: view4];

only a guess.

Regards Mark
 
OP
P
Joined
May 18, 2012
Messages
5
Reaction score
0
Points
1
Mark, your guessing works, it works that what i have done before ...

i need now to know how to set back the RootViewController to view1 the original RootViewController and all is done :)

what do you mean how the diffrent class files interact in your project? i will try to explain you everything hoping i will sleep again calm at night ... i'm disperated really
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
What I meant by how your project files interact is, how many view controllers and there names, how many windows, and where are you making these method calls from, without
this info it makes it very hard for someone to help you.

Can you not make the exact same method call I posted on the veiw1 instead of of veiw4?

Mark
 
OP
P
Joined
May 18, 2012
Messages
5
Reaction score
0
Points
1
ok mark, this night i figured out, i made a segue to this viewcontroller from the rootviewcontroller and everything is working fine ... thanks so much for your help...
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top