我是Xcode编程的新手,并且无法通过按下按钮来了解如何调用SecondViewController
窗口。按钮叫做Ingredients;我尝试在-(IBAction)Ingredients:(id)sender;
中输入“ViewController.h
但后来看到有FirstViewController.h
和SecondViewController.h
,与第一个和第二个ViewControllers
相同。
无论如何,我想要做的是能够点击“成分”按钮并使其进入一个完全不同的窗口,具有不同的背景,而其他文本作为第一个。我不确定我是否正确解释自己:(。让我尝试一下图片:
答案 0 :(得分:3)
首先,获取一些关于Objective C
的基本知识。转到Apple开发人员网站,您将获得大量的教程和帮助;要学习的示例代码。
现在,针对您的问题: -
在firstViewController.m
First import SecondViewController.h
点击按钮: -
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
答案 1 :(得分:1)
我可以看到你没有使用故事板,所以只需致电:
FLSecondViewController *object = [[FLSecondViewController alloc] initWithNibName:@"FLSecondViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:object animated:YES];
答案 2 :(得分:1)
为什么要去另一个窗口?视图控制器可能就足够了,设置导航控制器并推送第二个视图控制器。
答案 3 :(得分:0)
- (IBAction)Ingredients:(id)sender
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:secondViewController animated:YES];
}
编辑:典型的iOS应用程序只有一个窗口作为视图的容器,因此您大部分时间只能使用视图。根据要呈现的所需内容将一个视图更改为另一个视图。