1

There is a button at the viewcontroller and when i click the button pushviewcontroller doesn't work.


my appdelegate.m file :

- (BOOL)applicationUIApplication *)application **didFinishLaunchingWithOptionsNSDictionary** *)launchOptions 
{
    self.window = [[UIWindow alloc] initWithFrame:EK_SCREEN_BOUNDS];

    ExampleViewController *exampleViewController = [ExampleViewController new];

    self.window.rootViewController = exampleViewController;

   [self.window makeKeyAndVisible];

   return YES;
}

Button click method (in ExampleViewController):

mainViewController *frm = [mainViewController new];
[self.navigationController pushViewController:frm animated:YES];

How i can fire button click event ?

1
  • its hard to read what you actually need, please use the formatting tools and rephrase your question Commented Jun 23, 2015 at 6:15

4 Answers 4

1

Update your AppDelegate.m file with following code

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ExampleViewController *exampleViewController = [ExampleViewController new];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:exampleViewController];
self.window.rootViewController = navController;
//self.window.backgroundColor = [UIColor lightGrayColor];
[self.window makeKeyAndVisible];

The problem is that you are not initializing rootViewController from navigation controller. So, when you push a view controller on navigation controller it doesn't work. Because you never initialize a navigation controller.

Sign up to request clarification or add additional context in comments.

6 Comments

okey thank you for reply. i do what you say then i click the button openning page is whole black. its not my viewcontroller. what is your opinion
what is in your mainViewContorller? and also use coding convention like instead of mainViewContorller use file name as MainViewController
there is any code in my viewcontroller i just only i see my storyboard
can you share screenshot of storyboard or code inside your myviewcontroller?
-(void)viewDidLoad{ [super viewDidLoad]; nslog(@"its done"); } thats all :)
|
0

you need to change in appDelegate.m, need to set navigation controller as root view.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:EK_SCREEN_BOUNDS];

ExampleViewController *exampleViewController = [ExampleViewController new];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:exampleViewController];
self.window.rootViewController = navigation;

[self.window makeKeyAndVisible];

return YES;
}

Comments

0

You need to first add your ExampleViewController to UINavigationController as below

ExampleViewController *exampleViewController = [ExampleViewController new];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:exampleViewController];

self.window.rootViewController = exampleViewController;

After this you can do

mainViewController *frm = [mainViewController new]; [self.navigationController pushViewController:frm animated:YES];

1 Comment

i added navigationcontroller in my appdelegate file then when i click the button works but openning the viewcontroller is not my viewcontroller.Because its whole black.
0

Swift version of what Latit mentioend:

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        let screenBounds:CGRect = UIScreen.mainScreen().bounds

        var viewController:UIViewController = ViewController();

        self.window = UIWindow(frame: screenBounds);
        var nav:UINavigationController = UINavigationController(rootViewController: viewController);

        self.window?.rootViewController = nav;
        self.window?.makeKeyAndVisible();
       return true
    }
}

more info: http://www.ryanwright.me/cookbook/swift/ui-library/uinavigationcontrolle/set-root-controller

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.