如何根据分段控件和添加按钮切换到2个视图? [英] How do I segue to 2 views based on a Segmented Control and an Add button?
问题描述
我在导航控制器的标题中有一个分段控件,我想将一个对象添加到也在此导航控制器中的表视图控制器中。
I have a segmented control in the header of a navigation controller, I want to add an object to a table view controller thats also in this navigation controller.
我的问题出现在哪里:
如何从一个[+] UIButton切换到1个2个视图,每个分段控件选项的不同添加视图。你只能从故事板中的UIBarButtonItem挂起一个segue,但我不确定如果我只挂了一个然后在某处更改代码或者如果我必须构建单独的xib文件(我不熟悉,我是iPhone开发人员的新手或者它是如何工作的!
How do I segue from one [+] UIButton to 1 of 2 views, a different add view for each segmented control option. You can only hook up one segue from a UIBarButtonItem in the storyboard, but I wasn't sure If i just hook one up and then change the code somewhere or if i have to build separate xib files (which I'm not familiar with, I'm new to iPhone dev) or how this would work!
请帮忙!
推荐答案
你做了我称之为通用的segue,它与动作/触发器无关。请在此处查看我的答案:如何制作和使用通用segue
You make what I call "generic" segues that are not associated with an action/trigger. See my answer here: How to make and use generic segue
制作其中2个segue,然后在您的IBAction方法中进行segmentedControl调用 performSegueWithIdentifier:
。例如:
Make 2 of these segues, then in your IBAction method for your segmentedControl call performSegueWithIdentifier:
. For example:
- (IBAction)segmentCtrlChanged:(id)sender {
UISegmentedControl *seg = sender;
if (seg.selectedSegmentIndex == 0)
[self performSegueWithIdentifier:@"segue1" sender:self];
else if (seg.selectedSegmentIndex == 1)
[self performSegueWithIdentifier:@"segue2" sender:self];
}
这篇关于如何根据分段控件和添加按钮切换到2个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!