2012-01-09 76 views
1

当我使用segues推送视图(直接通过在故事板上拖动它)可以正常工作,并且加载下一个视图。然而,当我尝试实现这一切编程推视图时我对PIN的右箭头点击(在地图),我有点困惑:pushViewController无法以编程方式与故事板一起工作

编辑

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
    NSLog(@"calloutAccessoryControlTapped: enseigneDeLaStation"); 
    [self performSegueWithIdentifer:@"You identifier" sender:self]; 
} 

我得到这个错误:

Receiver Type 'MyFirstViewController' for instance message does not declare a method with selector performSegueWithIdentifer:sender: 

回答

5

你必须使用UIViewController小号实例方法performSegueWithIdentifier:sender:。它以编程方式从视图控制器的storyboard文件中以指定的标识符启动segue。

Here is the documentation

示例代码将是:(假设你是在一个视图控制器调用此

[self performSegueWithIdentifier:@"Your identifier" sender:self]; 

因此,对于你的代码将是:

-(IBAction)goToNextView{ 
    NSLog(@"The button is clicked"); 
    [self performSegueWithIdentifier:@"Your identifier" sender:self]; 
} 

不要忘记设置SEGUE标识符,并确保在代码和接口生成器中都具有相同的标识符

+0

嗨Pfitz,请你说明一个使用例子吗? thanx – Malloc 2012-01-09 13:20:01

+0

Hi @Malek。我更新了我的答案,并希望现在更清楚 – Pfitz 2012-01-09 13:54:28

+0

Pfitz,实际上,我在评论之前尝试了它,但出现错误:实例消息的Receiver Type'MyFirstViewController'没有声明与选择器相关的方法performSegueWithIdentifer:sender:',also also ,我尝试在使用地图时单击PIN的右箭头时推送视图,因此我的代码位于'calloutAccessoryControlTapped'方法中,我将更新我的帖子以使我的问题清晰。 – Malloc 2012-01-09 14:05:23

3

Malek是正确的Pfitz示例确实返回

Receiver Type 'MyFirstViewController' for instance message does not declare a method with selector performSegueWithIdentifer:sender:

这是由于输入错误。正确的方法是

[self performSegueWithIdentifier:@"You identifier" sender:self]; 
相关问题