2014-09-29 78 views
0

我有一个UIPageViewController并在其中有一个按钮。无论何时按下按钮,我想从父视图控制器(其中嵌入导航控制器)执行Segue到导航堆栈中的下一个视图控制器。我也希望能够通过segue传递数据。我尝试了几件事,但我对iOS开发非常陌生,一直都没有成功。从UIPageViewController的根视图控制器执行Segue

+0

我发现本教程很有帮助http://www.techotopia.com/index.php/An_Example_iOS_7_UIPageViewController_Application – 2014-09-29 17:36:46

+0

这是一个有用的教程,但在这里确实不相关。我有页面设置,它的工作完美。我只是在PageViewController中设置了一个IBAction,并且需要从父级执行Segue来查看IBAction何时被调用。 – 2014-09-29 17:45:30

+0

那么你在故事板中添加了按钮?如果是这样,你不需要一个IBAction方法。只需右键单击按钮并拖动到下一个视图控制器并选择“推”。 – 2014-09-29 17:53:37

回答

0

您需要选择故事板中的segue,并为其指定一个唯一的标识符并将其放在下面的代码中。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 

if ([segue.identifier isEqualToString:@"YourSegueIdentifier"]) { 
    // get a reference to the destination View Controller 
    UIViewController *destinationVC = [segue destinationViewController]; 
    XXYourViewControllerSubclass *yourVC = (XXYourViewControllerSubclass*)destinationVC; 
    // create the data and pass it to the view controller 
    id someData = // create your data (unless you have a property holding it already) 
    [yourVC acceptData:(id)someData]; // make a public method on your VC subclass to accept the data 
} 
// after this method has returned the seque will be performed 
} 

这有道理吗?

+0

非常感谢。得到它的工作。 – 2014-09-29 19:16:34

+0

太棒了。别客气。 – 2014-09-29 19:45:52

+0

你可不可以把它写成swift?我无法转换此代码 – XcodeNOOB 2015-02-14 12:00:33

相关问题