3

I am trying to navigate from UIViewController class (name is CartViewController)to Appdelegate (name is SimpleDemoAppDelegate) by clicking on Button.

The method and code for IBAction on button is

-(IBAction) Go
{
    AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
    UIViewController* presentingViewController = appDelegate.viewController;
}

I have also tried

-(IBAction) Go
{
    SimpleDemoAppDelegate *appdelegate=(SimpleDemoAppDelegate *)[UIApplication sharedApplication].delegate;
    [self.navigationController presentModalViewController:appdelegate animated:YES];
}

and pushViewController too, But it shows warning.

Incompatible pointer type sending 'SimpleDemoAppDelegate *' to parameter of type 'UIViewController *'

Can someone explain to me why I see this warning?

Morion
  • 10,495
  • 1
  • 24
  • 33
Ajit Satarkar
  • 717
  • 6
  • 20
  • 1
    I think you can not navigate to `AppDelegate` class. Its called very first when app is launched and generally used to store global variables and functions.. just call those methods and variables from any class... – rohan-patel Jun 07 '12 at 07:22
  • What do you mean by navigate to AppDelegate...? is [self.navigationController popToRootViewController]; the one you are exepecting? – xingzhi.sg Jun 07 '12 at 07:29
  • I have also tried..SimpleDemoAppDelegate *obj=[[SimpleDemoAppDelegate alloc]init]; [self.navigationController pushViewController:obj animated:YES] – Ajit Satarkar Jun 07 '12 at 07:30
  • @anonymous Actually I am trying to integrate two different demo app. – Ajit Satarkar Jun 07 '12 at 07:33
  • AppDelegate class is not a view controller. You can navigate only to a view controller. see this link to know about appdelegate http://stackoverflow.com/questions/652460/what-is-the-appdelegate-for-and-how-do-i-know-when-to-use-it – Warrior Jun 07 '12 at 07:34
  • @anonymous Actually I am new to iOS and trying to integrate two different demo app, i have added all the files of second app to first. Now i have button by clicking on which my compiler has to jump to second demo app where at start SimpleDemoAppdelegate is – Ajit Satarkar Jun 07 '12 at 07:39
  • @xingzhi.sg thanks i tried that one to but didnt work, Actually I am new to iOS and trying to integrate two different demo app, i have added all the files of second app to first. Now i have button by clicking on which my compiler has to jump to second demo app where at start SimpleDemoAppdelegate is – Ajit Satarkar Jun 07 '12 at 07:39
  • 1
    For this requirement, you probably should reconsider the way to switch between the two app mode. You can only have one AppDelegate - so you need to merge the two appDelegates into one. You can consider -setRootViewController (UIWindow) as a way to switch between app modes – xingzhi.sg Jun 07 '12 at 07:44
  • @xingzhi.sg yes you understand me well. please suggest me some proper links where i can refer solution for the same. Thanks – Ajit Satarkar Jun 07 '12 at 07:59
  • @xingzhi.sg I will check it -setRootViewController (UIWindow) – Ajit Satarkar Jun 07 '12 at 08:00
  • @xingzhi.sg Thanks it works fine now.. Properly merging was needed so single appDelegate must be there. – Ajit Satarkar Jun 08 '12 at 14:15

1 Answers1

0

i think you forgot to write viewcontroller property of appDelegate see this

SimpleDemoAppDelegate *appdelegate=(SimpleDemoAppDelegate *)[UIApplication sharedApplication].delegate;
[self.navigationController presentModalViewController:appdelegate.viewController animated:YES];
Saad
  • 8,857
  • 2
  • 41
  • 51