简体   繁体   English

Touchupinside和简单的viewController问题

[英]Touchupinside and simple viewController question

I've got a very simple viewController question . 我有一个非常简单的viewController问题。

I've got a main view with 2 buttons, upon touchupinside of a button I would like to load a new view Controller ( a table view ) . 我有一个带有2个按钮的主视图,在按钮的touchupinside上,我想加载一个新的View Controller(一个表视图)。

I've created a new viewController with its nib file . 我已经创建了一个新的viewController及其nib文件。

Created an IBAction like this that I've linked the button to in IB : 像这样创建了一个IBAction,将按钮链接到IB:

- (IBAction)displayVin {

    UIViewController *vinController = [[UIViewController alloc] initWithNibName:@"vinController" bundle:nil];
    [self.navigationController pushViewController:vinController animated:YES];
    [vinController release];

}

It's not doing anything therefore I must be forgetting something, but what ? 它什么也没做,因此我必须忘记一些东西,但是呢? should I declare this newViewController somewhere else ? 我应该在其他地方声明此newViewController吗? It's compiling and executing fine with no error message . 它的编译和执行都很好,没有错误消息。

UPDATE: 更新:

I'm now using this : 我现在正在使用这个:

- (IBAction)displayVin:(id)sender {

    NSLog(@"here");
    UIViewController *vinController = [[UIViewController alloc] initWithNibName:@"vinController" bundle:nil];
    [self.navigationController pushViewController:vinController animated:YES];
    [vinController release];

}

But it's crashing with this error when I press the button : 但是当我按下按钮时,它崩溃并显示此错误:

[displayVin]: unrecognized selector sent to instance 0x8d03000 * * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[displayVin]: unrecognized selector sent to instance 0x8d03000'* [displayVin]:无法识别的选择器已发送至实例0x8d03000 * *由于未捕获的异常'NSInvalidArgumentException'而终止了应用程序,原因:'-[displayVin]:无法识别的选择器已发送至实例0x8d03000'*

Should I be declaring something somewhere else , or "should" that bit of code be enough ? 我应该在其他地方声明,还是“应该”足够的代码?

Start by using NSLog() to determine if you're actually inside the displayVin() routine. 首先使用NSLog()确定您是否真正进入displayVin()例程。 Button events send a parameter to the acion, so you should probably declare it as -(IBAction)displayVin:(id)sender instead of just -(IBAction)displayVin . 按钮事件会将参数发送给acion,因此您应该将其声明为-(IBAction)displayVin:(id)sender而不是仅-(IBAction)displayVin

For your updated code, you might have to reconnect the IBOutlet in the IB file. 对于更新的代码,您可能必须重新连接IB文件中的IBOutlet。 It looks like it's still calling the [viewController displayVin] method (without arguments), instead of the [viewController displayVin:] 看起来它仍然在调用[viewController displayVin]方法(不带参数),而不是[viewController displayVin:]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM