UIAlertView in AppDelegate have to call Method in ViewController

Discussion in 'iOS Programming' started by poke, May 18, 2012.

  1. poke macrumors newbie

    Joined:
    May 18, 2012
    #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
     
  2. poke thread starter macrumors newbie

    Joined:
    May 18, 2012
    #2

    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 :(
     
  3. Ides macrumors member

    Joined:
    Mar 27, 2012
    #3
    Crash

    Are you sure you should be calling [self release]? Twice?

    That seems very bad. If you try to switch back to this view it will crash because the view controller has been improperly deallocated.
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    In Xcode, click on the menu "Product" in the menubar. Select the item "Edit Scheme". Under "Diagnostics", you should have "Enable Zombie Objects" checked off. If you do this, you will receive a warning whenever an object that has been dealloced is sent a message. (either because you released too often, as I suspect you did, or because you didn't retain as often as you should have.)
     

Share This Page