单击按钮移至iOS中的另一个视图控制器 [英] Moving to another view controller in iOS on Button Click

查看:75
本文介绍了单击按钮移至iOS中的另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对iOS还是很陌生,但我仍在尝试掌握一切。我正在XCode 5中尝试这个简单的程序,当用户单击按钮时,他将被重定向到另一个视图控制器。我做了其他论坛告诉其他询问者的操作,但是似乎遇到了错误。

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.

这是我的代码:

在ViewController.m中:

In ViewController.m:

- (IBAction)button1:(id)sender {

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

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

我在标题中放置了一个导入 WebServiceViewController.h。

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

这是错误(不是IDE错误消息,但也不成功):

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

这里是个例外:

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) 

此外,我正在使用情节提要。我有一个用户登录的初始场景。该场景中嵌入了一个导航控制器。登录后,我将不再使用segue,因为可以加载多个视图控制器,具体取决于已登录的用户类型。我正在尝试执行此简单程序,因为我将使用它

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.

编辑:

这对我有用

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

storyboardWithName取决于情节提要的名称。

storyboardWithName depends on the storyboard's name.

推荐答案

尝试以下操作:

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

还将Identityboard Inspector中的storyboardId设置为WebServiceViewController

also set storyboardId to WebServiceViewController in Identity Inspector

这篇关于单击按钮移至iOS中的另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆