Moving to another view controller in iOS on Button Click

christianleroy

I am very new to iOS and I am still trying to grasp things. I am trying out this simple program in XCode 5 where when a user clicks the button, he will be redirected into another view controller. I did what other forums told other askers to do, but I seem to encounter an error.

Here are my codes:

In ViewController.m:

- (IBAction)button1:(id)sender {

    WebServiceViewController *wc = [[WebServiceViewController alloc] 
           initWithNibName:@"WebServiceViewController" 
           bundle:nil];

    [self.navigationController pushViewController:wc animated:YES];
}

I placed an import "WebServiceViewController.h" in the headers.

Here is the error (not an IDE error message, but not a success either):

enter image description here

Here is the exception:

2013-10-25 02:05:51.904 sample[16318:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Guest/Library/Application Support/iPhone Simulator/7.0/Applications/C6FA1F33-5E11-40C2-8C69-DA368F21CA5F/sample.app> (loaded)' with name 'WebServiceViewController''
*** First throw call stack:
(
    0   CoreFoundation                      0x017345e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014b78b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017343bb +[NSException raise:format:] + 139
    3   UIKit                               0x004ca65c -[UINib instantiateWithOwner:options:] + 951
    4   UIKit                               0x0033cc95 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    5   UIKit                               0x0033d43d -[UIViewController loadView] + 302
    6   UIKit                               0x0033d73e -[UIViewController loadViewIfRequired] + 78
    7   UIKit                               0x0033dc44 -[UIViewController view] + 35
    8   UIKit                               0x00357a72 -[UINavigationController _startCustomTransition:] + 778
    9   UIKit                               0x00364757 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
    10  UIKit                               0x00365349 -[UINavigationController __viewWillLayoutSubviews] + 57
    11  UIKit                               0x0049e39d -[UILayoutContainerView layoutSubviews] + 213
    12  UIKit                               0x00294dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    13  libobjc.A.dylib                     0x014c981f -[NSObject performSelector:withObject:] + 70
    14  QuartzCore                          0x03aee72a -[CALayer layoutSublayers] + 148
    15  QuartzCore                          0x03ae2514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    16  QuartzCore                          0x03ae2380 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    17  QuartzCore                          0x03a4a156 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    18  QuartzCore                          0x03a4b4e1 _ZN2CA11Transaction6commitEv + 393
    19  QuartzCore                          0x03a4bbb4 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    20  CoreFoundation                      0x016fc53e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    21  CoreFoundation                      0x016fc48f __CFRunLoopDoObservers + 399
    22  CoreFoundation                      0x016da3b4 __CFRunLoopRun + 1076
    23  CoreFoundation                      0x016d9b33 CFRunLoopRunSpecific + 467
    24  CoreFoundation                      0x016d994b CFRunLoopRunInMode + 123
    25  GraphicsServices                    0x036859d7 GSEventRunModal + 192
    26  GraphicsServices                    0x036857fe GSEventRun + 104
    27  UIKit                               0x0022a94b UIApplicationMain + 1225
    28  sample                              0x00002e7d main + 141
    29  libdyld.dylib                       0x01d70725 start + 0
    30  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Furthermore, I'm using storyboard. I have an initial scene where the user logs in. This scene has a navigation controller embedded. After logging in, I'm not gonna use segue since there would be several view controllers that can be loaded, depending on what type of user has logged in. I'm trying to do this simple program since I'm gonna be using it more complexly in the future.

I'm obviously missing something. I hope someone can help me. I'd be very grateful.

EDIT:

This worked for me

WebServiceViewController *wc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]
  instantiateViewControllerWithIdentifier:@"WebServiceViewController"];
  [self.navigationController pushViewController:wc animated:YES];

storyboardWithName depends on the storyboard's name.

ChikabuZ

try this:

WebServiceViewController *wc = [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"WebServiceViewController"];

also set storyboardId to WebServiceViewController in Identity Inspector

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Moving From one tab view to another by button Click Android ActionBar

From Dev

How to navigate to another view controller by click on button in collection view cell

From Dev

Move a View into Another view on button click in Swift iOS

From Dev

Move a View into Another view on button click in Swift iOS

From Dev

Passing parameters on button click in strongly-typed view to another controller

From Dev

Xamarin IOS navigate to another view controller without button on xamarin

From Dev

Keep TabBar when moving to another view controller

From Dev

Moving View Controller to the top of navigation stack iOS

From Dev

MVC view button click event , Pass AngularJs object to another MVC Controller

From Dev

Xamarin iOS Binding Library View Controller Button Click Crashes Xamarin form App

From Dev

How to access a button from another view controller?

From Dev

how to check button state in another view controller

From Dev

Ios Swift : Adding or Moving NavigationBar to bottom of the view controller

From Dev

is it possible to click a button, while it is moving, using animations in iOS?

From Dev

iOS - pass data to another view controller

From Dev

IOS how to segue an array to another view controller

From Dev

iOS Storyboard - Switch View to another view controller at same hierarchical level

From Dev

How to refresh a table view from another view controller iOS?

From Dev

how to call tab bar view controller by click button function in swift

From Dev

How to open new view controller after click button?

From Dev

MVC pass int from view to controller with a button click

From Dev

Android image moving on button click

From Dev

Button click not moving to the new activity

From Dev

How to hide button from one view controller to another

From Dev

Cannot navigate from one view controller to another with button

From Dev

Do something on button tap then segue to another view controller

From Dev

Disable Button from another view controller with a switch with swift

From Dev

Swift: Need to move data stored using a button to another View Controller

From Dev

Swift IOS: several buttons in one view controller, control the image view display in another view controller

Related Related

  1. 1

    Moving From one tab view to another by button Click Android ActionBar

  2. 2

    How to navigate to another view controller by click on button in collection view cell

  3. 3

    Move a View into Another view on button click in Swift iOS

  4. 4

    Move a View into Another view on button click in Swift iOS

  5. 5

    Passing parameters on button click in strongly-typed view to another controller

  6. 6

    Xamarin IOS navigate to another view controller without button on xamarin

  7. 7

    Keep TabBar when moving to another view controller

  8. 8

    Moving View Controller to the top of navigation stack iOS

  9. 9

    MVC view button click event , Pass AngularJs object to another MVC Controller

  10. 10

    Xamarin iOS Binding Library View Controller Button Click Crashes Xamarin form App

  11. 11

    How to access a button from another view controller?

  12. 12

    how to check button state in another view controller

  13. 13

    Ios Swift : Adding or Moving NavigationBar to bottom of the view controller

  14. 14

    is it possible to click a button, while it is moving, using animations in iOS?

  15. 15

    iOS - pass data to another view controller

  16. 16

    IOS how to segue an array to another view controller

  17. 17

    iOS Storyboard - Switch View to another view controller at same hierarchical level

  18. 18

    How to refresh a table view from another view controller iOS?

  19. 19

    how to call tab bar view controller by click button function in swift

  20. 20

    How to open new view controller after click button?

  21. 21

    MVC pass int from view to controller with a button click

  22. 22

    Android image moving on button click

  23. 23

    Button click not moving to the new activity

  24. 24

    How to hide button from one view controller to another

  25. 25

    Cannot navigate from one view controller to another with button

  26. 26

    Do something on button tap then segue to another view controller

  27. 27

    Disable Button from another view controller with a switch with swift

  28. 28

    Swift: Need to move data stored using a button to another View Controller

  29. 29

    Swift IOS: several buttons in one view controller, control the image view display in another view controller

HotTag

Archive