【问题标题】:Navigationcontroller don't work fine导航控制器不能正常工作
【发布时间】:2013-02-14 10:16:48
【问题描述】:

我(希望)有一个小问题。 rightCalloutAccessoryView 按钮方法。我尝试将navigationcontroller 推送到another viewcontroller,但它不能正常工作。我总是黑屏。 navigationBar 被禁用

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// ... code ...
        pinAnnotationView.canShowCallout = YES;
        UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [detailButton addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside];
        pinAnnotationView.rightCalloutAccessoryView=detailButton;
// ... code ...
}

按钮:

-(IBAction)showDetailView:(UIButton *)sender
{
    InfoViewController *infoView = [[InfoViewController alloc] init];
    [self.navigationController pushViewController:infoView animated:YES];

    NSLog(@"pushed Button!!!!!!");

}

我的目标:ViewControllerdetailButton 并推送到InfoViewController

也许这只是一个小错误,我没有发现。

【问题讨论】:

  • init 方法,你不是使用 xib 文件吗?像 -initWithNibName:bundle
  • 我没有任何 xib 文件,因为我正在使用情节提要
  • 但是如果你不告诉加载什么资源文件,sdk怎么知道加载什么?您必须在 initWithNib 方法中给出 xib 文件的名称。使用 InfoViewController *infoView = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];或使用 [self.storyboard instantiateViewControllerWithIdentifier:@"InfoViewController"];
  • 两者都不适合我:doesn't contain a view controller with identifier 'InfoViewController'Could not load NIB in bundle: 'NSBundle with name 'infoViewController'

标签: ios uibutton mkmapview mkannotation


【解决方案1】:

如果您的 InfoViewController 在情节提要中,那么您需要获取那个,而不是使用 alloc init 创建一个新的。 InfoViewController 需要故事板中的标识符,然后您可以像这样实例化它:

InfoViewController *infoView = [self.storyboard instantiateViewControllerWithIdentifier:@"InfoViewController"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    • 2013-07-29
    • 1970-01-01
    • 2021-10-18
    • 2012-04-01
    相关资源
    最近更新 更多