通过按钮将一个视图链接到另一个视图 [英] Linking One View To Another Via A Button

查看:109
本文介绍了通过按钮将一个视图链接到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对iOS编程有点新意,我在通过按钮将一个视图链接到另一个视图时遇到了一些麻烦。我只是创建了一个简单的小应用程序,它在NSDate上进行一些计算,试图学习XCode和iOS编程。

I'm a bit new to programming for iOS, and I'm having some trouble linking one view to another via a button. I'm just creating a simple little app that does some calculations on a NSDate in an attempt to learn XCode and iOS programming.

我已经搜索了这么多,我试图从其他例子中学习,但我无法让视图呈现,当我按下我的按钮(我已经检查过链接到按钮)时没有任何反应。

I've already searched this quite a bit, and I've tried to learn from other examples but I'm having trouble getting the view to present, nothing happens when I press my button (which I've already checked to be linked to the button).

我一直无法理解视图编程,所以请耐心等待。

I've been having trouble understanding view programming, so please bear with me.

这是我的代码我的按钮:

Here's my code for my button:

-(IBAction)resultsPressed
{
    TimeResults *timeResults;
    timeResults = [[TimeResults alloc] initWithNibName:@"TimeResults" bundle:nil];
    [self.navigationController pushViewController:timeResults animated:YES];
    [timeResults release];
}

如果重要的话TimeResults.xib正在使用导航控制器,而我的根视图只是一个观点。我这背后的想法是,我可以得到后退按钮(虽然我不确定这是否是正确的方法,因为它们不是同一层次结构的一部分)。关于如何做到这一点的任何建议将不胜感激!

TimeResults.xib is using a Navigation Controller if it matters, while my root view is simply a view. My thinking behind this was so that I could get the "back" button (though I'm not sure if this is the correct way tot do this, since they are not a part of the same hierarchy). Any suggestions on how this should be done would be greatly appreciated!

推荐答案

您发布的代码似乎没有任何问题,但您应该将导航控制器与第一个笔尖关联,因为当新视图被推入堆栈时,默认显示后退按钮。

Nothing seems wrong with the code you posted, but you should have the Navigation Controller associated with the first nib, as the back button will display by default when a new view is pushed onto the stack.

此外,请确保导航控制器已在 AppDelegate 中正确设置。如果您启动新项目并选择基于导航的应用程序,则可以看到执行此操作的正确方法。如果您使用新项目作为示例向您展示如何正确设置旧项目,则必须确保 nib 也正确设置。我建议使用新项目,将其挂钩为 UIViewController 而不是 UITableViewController ,然后将代码从旧项目移动到新项目。

Also, make sure that the Navigation Controller is set up properly in your AppDelegate. The proper way to do this can be seen if you start a new project and select "Navigation-based Application". If you use the new project as a sample to show you how to set up your old project correctly, you will have to make sure that the nib is set up correctly too. I would suggest using the new project, hooking it up as a UIViewController instead of a UITableViewController, and then moving your code from your old project to this new one.

最后,确保始终导入 .h UIViewController 的文件。希望有所帮助!

Finally, make sure that you always import the .h file of the UIViewController you are going to push to. Hope that helps!

这篇关于通过按钮将一个视图链接到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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